douzi0609 2012-05-30 03:07
浏览 75
已采纳

困难的算法:徽章平衡,数学分布

I have a quite interesting problem that's making my head twist. I'm working on a small system consisting of users and awards (called badges). There is a special badge that is awarded to users depending on the following criteria: 10 bronze badges, 5 silver badges and 1 gold badge. That is pretty simple, however, if an user has 8 bronze badges, 7 silver badges and 1 gold badge, he can use his 2 additional silver badges as bronze ones.

This happens everytime the user has available "higher" badges to distribute. Again, for example, if he has 8 bronze badges, 4 silver badges and 4 gold badges, he can "transform" 2 of his gold badges into bronze and 1 to silver, in order to earn the special badge.

I have absolutely no idea of how to do this. I've tried with various loops, ifs, but i can never distribute properly. Maybe someone can help me out?

  • 写回答

3条回答 默认 最新

  • doushi7314 2012-05-30 03:09
    关注

    The user needs at least 1 gold badge, at least 6 badges that are either silver or gold, and at least 16 badges that are bronze, silver or gold.

    The pseudocode is

    count(gold) >= 1
    && count(gold) + count(silver) >= 6
    && count(gold) + count(silver) + count(bronze) >= 16
    

    If you also have a diamond medal that can swap for a gold, silver or bronze then include that as well, like

    count(diamond) + count(gold) >= 1
    && count(diamond) + count(gold) + count(silver) >= 6
    // etc
    

    Or you could use a 'medal rank' so that you can do something simpler like

    count(rank of gold or higher) >= 1
    && count(rank of silver or higher) >= 6
    && count(rank of bronze or higher) >= 16
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式