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条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路