• 理解要跟得上~


    描述

    As is known to all,if you throw a coin up and let it droped on the desk there are usually three results. Yes,just believe what I say ~it can be the right side or the other side or standing on the desk, If you don't believe this,just try In the past there were some famous mathematicians working on this .They repeat the throwing job once again. But jacmy is a lazy boy.He is busy with dating or playing games.He have no time to throw a single coin for 100000 times. Here comes his idea,He just go bank and exchange thousands of dollars into coins and then throw then on the desk only once. The only job left for him is to count the number of coins with three conditions.

    He will show you the coins on the desk to you one by one. Please tell him the possiblility of the coin on the right side as a fractional number if the possiblity between the result and 0.5 is no larger than 0.003. BE CAREFUL that even 1/2,50/100,33/66 are equal only 1/2 is accepted ! if the difference between the result and 0.5 is larger than 0.003,Please tell him "Fail".Or if you see one coin standing on the desk,just say "Bingo" any way.

     
    输入
    Three will be two line as input. The first line is a number N(1<N<65536) telling you the number of coins on the desk. The second line is the result with N litters.The letter are "U","D",or "S","U" means the coin is on the right side. "D" means the coin is on the other side ."S" means standing on the desk.
    输出
    If test successeded,just output the possibility of the coin on the right side.If the test failed please output "Fail",If there is one or more"S",please output "Bingo"
    样例输入
    6
    UUUDDD
    样例输出
    1/2
    
    //204
    #include <stdio.h>
    #include <math.h>
    int main()
    {
        int num, i, u, st;
        char s;
        u = st = 0;
        scanf("%d", &num);
        getchar();
        for(i = 1; i <= num; i++){
    
                scanf("%c", &s);
                if(s == 'U')
                {
                    u++;/*u代表up状态的硬币数*/
                }
            //    else if(s == 'D') //down的数目没有用,我省去,以减少判断次数
            //    {
            //        d++;/*d代表down状态的硬币数*/
            //    }
                else if(s == 'S')
                {
                    st++;/*st代表站立状态的硬币数*/
                }
    
        }
        if(st != 0)
        {
            printf("Bingo
    ");
        }
        else if(fabs(u*1.0/num - 0.5) <= 0.003)
        {
        //        if(num == 2)
        //        {
        //            printf("Fail
    ");
        //        }
    #if 0    //理解错了:1/2,50/100,33/66 are equal only 1/2 is accepted 是指能约分约分
            if(u*1.0/num == 0.5)
            {
                u = 1;
                num = 2;
            }
            printf("%d/%d
    ", u, num);
    #endif
        
            for(i = 2; i <= u; i++){
    
                    while(u%i == 0 && num%i == 0)
                    {
                        u /= i;
                        num /= i;
                    }
    
            }
            printf("%d/%d
    ", u, num);
            
        }
        else
        {
            printf("Fail
    ");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    2014 年美国程序员薪资调查
    新加坡移民生活:想出都出不来了!
    mysql命令行参数
    甲骨文创始人埃里森的10大混蛋行为:曾翻微软垃圾堆
    为什么我要称自己为Javascript程序员
    原生JavaScript练习——弹出层
    Leetcode 344 Reverse String 字符串处理
    安装 Autoconf 2.69版
    Leetcode 28 Implement strStr()
    Leetcode 67 Add Binary 大数加法+字符串处理
  • 原文地址:https://www.cnblogs.com/the-one/p/3299390.html
Copyright © 2020-2023  润新知