zoukankan      html  css  js  c++  java
  • zoj 1003 Crashing Balloon(整数分解应用)

    Crashing Balloon

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    On every June 1st, the Children's Day, there will be a game named "crashing balloon" on TV.  The rule is very simple.  On the ground there are 100 labeled balloons, with the numbers 1 to 100.  After the referee shouts "Let's go!"the two players, who each starts with a score of  "1", race to crashthe balloons by their feet and, at the same time,multiply their scores by the numbers written on the balloons they crash. After a minute, the little audiences are allowed to take the remaining balloons away, and each contestant reports hisher score, the product of the numberson the balloons heshe's crashed.  The unofficial winner is the player whoannounced the highest score.

    Inevitably, though, disputes arise, and so the official winner is notdetermined until the disputes are resolved.  The player who claimsthe lower score is entitled to challenge hisher opponent's score.  Theplayer with the lower score is presumed to have told the truth, becauseif heshe were to lie about hisher score, heshe would surely come up with a biggerbetter lie.  The challenge is upheld if the player with the higherscore has a score that cannot be achieved with balloons not crashed by thechallenging player.  So, if the challenge is successful, the playerclaiming the lower score wins.

    So, for example, if one player claims 343 points and the other claims49, then clearly the first player is lying; the only way to score 343 isby crashing balloons labeled 7 and 49, and the only way to score 49 is by crashinga balloon labeled 49.  Since each of two scores requires crashing theballoon labeled 49, the one claiming 343 points is presumed to be lying.

    On the other hand, if one player claims 162 points and the other claims81, it is possible for both to be telling the truth (e.g. one crashes balloons2, 3 and 27, while the other crashes balloon 81), so the challenge would notbe upheld.

    By the way, if the challenger made a mistake on calculating his/her score, then the challenge would not be upheld. For example, if one player claims 10001 points and the other claims 10003, then clearly none of them are tellingthe truth. In this case, the challenge would not be upheld.

    Unfortunately, anyone who is willing to referee a game of crashing balloon islikely to get over-excited in the hot atmosphere that heshe could not reasonably be expected to perform the intricate calculationsthat refereeing requires.  Hence the need for you, sober programmer,to provide a software solution.

    Input

    Pairs of unequal, positive numbers, with each pair on a single line, thatare claimed scores from a game of crashing balloon.

    Output

    Numbers, one to a line, that are the winning scores, assuming that theplayer with the lower score always challenges the outcome.

    Sample Input

    343 49
    3599 610
    62 36
    
    

    Sample Output

    49
    610
    62 


    题目大义就是两个人踩一堆(100个)已经从1到100编号的气球,每个人得到的分数就是所踩气球编号的加和,判断规则:低分的总是会质疑高分的作假,作假就是得到的分数在进行整数分解的时候根本没法用 1到100之内的数实现,或者高分的在分解的时候必须的一个数值恰好低分的整数分解时也需要,因为每个数字只有一个,出现这种情况就意味着有人分数作假,假如高分作假,那么输出低分,低分作假输出高分,高分与低分同时作假也输出低分。


    AC代码:


    #include <cstdio>
    #include <iostream>
    #include <cstring>
    using namespace std ;
    bool aTrue,bTrue ;
    
    int judge(int m,int n,int p)
    {
        if(aTrue)
            return 0 ;    //挑战失败
        if(m == 1 && n==1)   //按照规则,只要高分者不说谎,则挑战失败,即高分者胜利
        {
            aTrue  = true ;
            return 0 ;
        }
        if(n ==1)
            bTrue = true ;   //此时n==1 && m!=1(即高分的分数无法有效分解,即高分者在说谎)
        while(p >1)
        {
            if(m%p == 0)   //p是m的一个因子
                judge(m/p,n,p-1) ;
            if(n%p == 0)   //p是n的一个因子
                judge(m,n/p,p-1) ;
            p -- ;
        }
        return 0 ;
    }
    
    int main()
    {
        int a,b ;
        while(scanf("%d%d",&a,&b)!=EOF)
        {
            if(a<b)
            {
                int t = a ;
                a = b;
                b = t ;
            }
            aTrue = false ;
            bTrue = false ;
            judge(a,b,100) ;
            if(!aTrue && bTrue)
            {
                printf("%d
    ",b) ;
            }
            else
            {
                printf("%d
    ",a) ;
            }
        }
        return 0 ;
    }
    


  • 相关阅读:
    NGINX高并发配置
    一致性哈希算法——PHP实现代码
    TCP三次握手详解
    一致性哈希算法——转载来自张洋
    ngx_http_upstream_keepalive
    高情商人的十一种表现
    Nginx中的upstream轮询机制介绍
    主从读写分离----mysql-proxy0.8.5安装与配置
    分布式事务XA
    微信小程序API
  • 原文地址:https://www.cnblogs.com/emoji/p/4436784.html
Copyright © 2011-2022 走看看