zoukankan      html  css  js  c++  java
  • nyoj 204-Coin Test (python count)

    204-Coin Test


    内存限制:64MB 时间限制:3000ms 特判: No
    通过数:2 提交数:2 难度: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
    

    python   AC:

     1 def gcd(a, b):
     2     if b == 0:
     3         return a
     4     return gcd(b, a % b)
     5 
     6 
     7 n = int(input())
     8 my_str = input()
     9 u = my_str.count("U")
    10 d = my_str.count("D")
    11 s = my_str.count("S")
    12 
    13 if s >= 1:
    14     print("Bingo")
    15 else:
    16     total = u + d
    17     ans = float(u) / float(total)
    18     if 0.497 <= ans <= 0.503:
    19         temp = gcd(u, total)
    20         print("%d/%d" % (u / temp, total / temp))
    21     else:
    22         print("Fail")
  • 相关阅读:
    jython运行python文件
    jython查看帮助help和模块modules
    ubuntu 星际译王3.0.1-9.4隐藏主界面不能打开
    ubuntu火狐(firfox)浏览器安装视频插件
    ubuntu安装mp4播放器vlc & smplayer
    ubuntu+Windows双系统默认引导顺序
    notepad++ 各种颜色调整
    Linux绿色版软件expect
    aix下shell读取脚本文件并逐行执行
    AIX系统常用命令
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9332867.html
Copyright © 2011-2022 走看看