Coin Test
来源:互联网 发布:互网络出版许可证 编辑:程序博客网 时间:2024/06/14 08:07
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"
- 样例输入
6UUUDDD
- 样例输出
1/2
package MainTest;import java.util.*;public class Main {static int gcd(int x, int y){if(x%y==0)return y;elsereturn gcd(y,x%y);} public static void main(String[] args) { Scanner in=new Scanner(System.in); int k=in.nextInt(); String s=in.next(); double cntU=0,cntS=0; for (int i = 0; i < s.length(); i++) {if(s.charAt(i)=='U')cntU++;if(s.charAt(i)=='S')cntS++; } if(cntS>=1) System.out.println("Bingo"); else{ if(cntU/k*1.0-0.5<=0.003){ int c=gcd((int)cntU,k); System.out.println(cntU==0?0:((int)cntU/c+"/"+k/c)); } else System.out.println("Fail"); } } } 注意分数的转换方法
- Coin Test
- Coin Test
- Coin test
- Coin Test
- coin test
- Coin Test
- Coin Test
- Coin Test
- Coin Test
- Coin Test
- Coin Test
- NYOJ - Coin Test
- nyoj-204Coin Test
- nyoj 204-Coin Test
- NYOJ 204 Coin Test
- nyoj-204Coin Test
- 204 Coin Test
- nyoj 204 Coin Test
- 微信小程序实例源码大全下载
- mfc textout显示字符串到窗口上
- wxWidgets+CodeBlocks Win平台搭建
- 关于python中中文字符切割乱码的问题
- tar.xz文件如何解压
- Coin Test
- redis安装配置(windows/linux)
- C#192课的主要内容
- 手把手教你如何搭建CTS测试环境---2、JDK安装和环境配置
- Safecracker
- 微信小程序实例源码大全下载
- Redis 3.2.1集群搭建
- 左神课堂开始
- zoj 3471 Most Powerful(状态压缩DP)