Coin Test
来源:互联网 发布:matlab优化工具箱在哪 编辑:程序博客网 时间:2024/06/11 02:49
- 描述
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
他把桌子上每枚硬币给你看。请你用分数的形式告诉他硬币正面朝上的概率(当该概率在0.003和0.5之间),注意1/2,50/100,33/66是相等的,但只有1/2的形式才能通过!假如该概率小于0.003或大于0.5,则告诉他"Fail",当然如果你看到有一枚硬币竖立,输出"Bingo"即可。
输入
有两行作为输入。
第一行是一个整数N(1<N<65536),表示桌子上硬币的个数。
第二行是表示用来表示硬币朝向的N个字母,它们是"U","D","S". "U"表示正面朝上,"D"表示正面朝下,"S"表示竖立。
输出
若该实验成功,输出正面朝上的概率。若失败,则输出"Fail",如果有一个或多个"S",输出"Bingo"
#include<stdio.h>int main(){int a,Bingo=0,i,k,b,c;//设置标志Bingo。不为0则输出Bingodouble right,left;scanf("%d\n",&a);//投掷硬币的总数char condition[a+10];gets(condition);for(i=0;i<a;i++){if(condition[i]=='U')right++;if(condition[i]=='D')left++;if((condition[i]=='S')||(condition[i]=='s'))Bingo=1;}if(Bingo==1)printf("Bingo\n");else{if((right*2)==a)printf("1/2\n");else{if((right/a<0.5)&&((right/a)>=0.003))//概率为0.5时输出1/2{b=right,c=a;//化简分子分母,约分for(k=2;k<=right;k++){if((b%k==0)&&(c%k==0))b=b/k,c=c/k,k=2;}printf("%d/%d\n",b,c);}elseprintf("Fail\n");}}return 0;}
- 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
- Myecplise搭建struts2环境时总是报错java.lang.ClassNotFoundException
- 【C/C++】从零开始的cmake教程
- 微信小程序——校园活动地图后端开发日志(2)
- Golang协程调度
- MySQL基础教程4-SQL基础概念
- Coin Test
- Android 全局弹出对话框SYSTEM_ALERT_WINDOW权限
- leetcode题解c++ | 76. Minimum Window Substring
- 数据结构与算法1.概念及术语
- Nginx安装
- 栈的应用之表达式求值(二)
- C# WinForm 中 MessageBox的使用详解
- Netty实现长连接简单例子
- 【Android实测】WebView的JS注入