zoukankan      html  css  js  c++  java
  • NYOJ204Coin Test

    Coin Test

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
     
    描述

    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
     
    #include<stdio.h>
    #include<string.h>
    int gcd(int a,int b)
    {
        int t;
        if(a<b)
        {t=a;a=b;b=t;}
        while(b)
        {
                t=a%b;
                a=b;
                b=t;
        }
        return a;
    }
    char str[65540];
    int main()
    {
        int n,t,i,countu,len;
        scanf("%d",&n);
           countu=0;
           scanf("%s",str);
           len=strlen(str);
           countu=0;
           for(i=0;i<len;i++)
           {
             if(str[i]=='U')
              countu++;
                if(str[i]=='S')
                {
                   printf("Bingo\n");
                  return 0;
                }
           }
           if(countu==0)
           {
           printf("0\n");return 0;
           }
           if(countu==len)
           {
            printf("1\n");return 0;
           }
           t=gcd(countu,len);
           printf("%d/%d\n",countu/t,(len)/t);
         return 0;
    }
           
            
  • 相关阅读:
    你的C/C++程序为什么无法运行?揭秘Segmentation fault (2)
    亲,这就是遗传算法
    我们为什么需要Map-Reduce?
    搜索引擎-架构概述(2)
    搜索引擎-架构概述(1)
    单源最短路径-迪杰斯特拉算法(Dijkstra's algorithm)
    最小生成树-普利姆算法eager实现
    最小生成树-普利姆算法lazy实现
    最小生成树-克鲁斯卡尔算法(kruskal's algorithm)实现
    索引式优先队列(indexed priority queue)
  • 原文地址:https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_2012_08_020.html
Copyright © 2011-2022 走看看