Nyoj 204-coin Test (python count)

Source: Internet
Author: User
Tags gcd

204-coin Test


Memory limit: 64MB time limit: 3000ms Special Award: No
Number of passes: 2 commits: 2 Difficulty: 1

Title Description:

As is known to all,if you throw a coin up and let it droped on the desk there is usually three results. Yes,just believe what I say ~it can is 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 on this. They repeat the throwing job once again. But Jacmy was a lazy boy. He is busy with dating or playing games. He has no time to throw a, coin for 100000 times. Here comes he idea,he just go bank and exchange thousands of dollars into coins and then throw in the desk only once . The only job left for him are to count the number of coins with three conditions.

He'll show you the coins on the desk-to-one by one. 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 this even 1/2,50/100,33/66 is equal only the IS accepted! If the difference between the result and 0.5 are larger than 0.003,please tell him "Fail". Or if you see one coin standing on the desk,just say ' Bingo ' any '.

Input Description:
Three would be as input. The first line was a number N (1<n<65536) telling you the number of coins on the desk. The second line was the result with N litters. The letter was "U", "D", or "S", "u" means the coin is in the right side. "D" means the coin is on the other side. " S "means standing on the desk.
Output Description:
If test Successeded,just Output The possibility of the coin on the right side. If the test failed. Output "Fail", if there is one or more "S", please output "Bingo"
Sample input:Copy
6UUUDDD
Sample output:
1/2

Python AC:

1 defgcd (A, b):2     ifb = =0:3         returna4     returnGCD (b, a%b)5 6 7n =int (input ())8My_str =input ()9U = My_str.count ("U")TenD = My_str.count ("D") Ones = My_str.count ("S") A  - ifS >= 1: -     Print("Bingo") the Else: -Total = U +D -Ans = float (u)/float (total) -     if0.497 <= ans <= 0.503: +temp =gcd (U, total) -         Print("%d/%d"% (u/temp, total/temp)) +     Else: A         Print("Fail")

Nyoj 204-coin Test (python count)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.