nyoj204Coin Test
来源:互联网 发布:golang template 编辑:程序博客网 时间:2024/06/06 00:17
Coin Test
- 描述
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
代码:
#include<stdio.h>#include<math.h>int main(){int hcf(int u,int v);int n,i;int x=0;int HCF=0;char str[65536];scanf("%d",&n);getchar();gets(str);for(i=0;i<n;i++){if(str[i]=='S'){printf("Bingo\n");break;}elseif(str[i]=='U')x++;}if(x==0)printf("Fail\n");else if(x%n==0)printf("%d\n",x/n);else{HCF=hcf(x,n);x=x/HCF;n=n/HCF;printf("%d/%d\n",x,n);}return 0;}int hcf(int u,int v){int t,r;if(v>u){t=v;v=u;u=t;}while((r=u%v)!=0){u=v;v=r;}return v;}
- nyoj204Coin Test
- NYOJ204coin text
- test
- test
- test
- test
- test
- test
- test
- Test
- test
- Test
- test
- test
- test
- test
- test
- test
- css美化 文件域
- ios初学的一些小知识(大手勿喷)
- HTTP Referer简介
- POJ 1328 Radar Installation(贪心)
- Android之NDK开发
- nyoj204Coin Test
- css参考手册
- http 缓存机制
- bootloader中添加emergency download mode
- 关于Java配置文件properties的使用(简单易用版)
- Heap & Priority Queue
- 手机APPUI界面设计流程
- 有趣的 VPN
- HW -- temp