Coin Test

Coin Test

时间限制:3000 ms  |  内存限制:65535 KB

难度: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

查看代码---运行号:252134----结果:Accepted

运行时间:2012-10-05 09:29:04  |  运行人:huangyibiao

view sourceprint?

01.#include <iostream>

02.#include <cmath>

03. 

04.using
namespace std;

05.#define MAX_LEN 65536

06.int
main()

07.{

08.int
nCoins;//硬币

09.char
str[MAX_LEN];

10. 

11.cin >> nCoins;

12.cin >> str;

13. 

14.int
u = 0, d = 0, s = 0;

15.for
(int
i = 0; str[i] !=
'\0'; i++)

16.{

17.if
(str[i] == 'U')

18.u++;

19.else
if (str[i] == 'D')

20.d++;

21.else
if (str[i] == 'S')

22.s++;

23.}

24.if
(s != 0)

25.{

26.cout <<
"Bingo\n";

27.}

28.else
if (fabs(1.0*u / (double)nCoins - 1.0/2.0) > 0.003)

29.{

30.cout <<
"Fail\n";

31.}

32.else

33.{

34.int
r, m = u, n = nCoins;//保存原来的变量值

35.while
(n)

36.{

37.r = m % n;

38.m= n;

39.n = r;

40.}

41.cout << u / m<<
"/" << nCoins / m << endl;

42.}

43.return
0;

44.}

时间: 2024-09-16 21:00:16

Coin Test的相关文章

UVa 11264 Coin Collector (选硬币&amp;amp;贪心好题)

11264 - Coin Collector Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2231 Our dear Sultan is visiting a country where there are n different types of coi

UVa 674 Coin Change (DP)

674 - Coin Change Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=615 Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent.

一家名叫Coin的公司刚刚推出了一种售价100美元的智能信用卡

一家名叫Coin的公司刚刚推出了一种售价100美元的"智能"信用卡,号称可以取代用户口袋里的所有银行卡. 乍一看,Coin智能信用卡与普通银行卡没有太大不同,花100美元买到的似乎只是一个简约版的 Coin智能信用卡:可取代所有银行卡 媒体来源:新浪科技 信用卡.与常规的借记卡和信用卡一样,它也可以在POS机上刷卡.但实际上,它却可以取代你钱包中的所有银行卡. 要把其他银行卡集成到Coin中,需要安装Coin应用,并使用配套的读卡器刷一下原有的银行卡.然后对着这张银行卡拍一张照,就可以

抛硬币模拟(Coin Tossing Simulation)

//Coin Tossing Simulation//Java how to program, 5/e, Exercise 6.30import javax.swing.*;import java.awt.*;import java.awt.event.*;public class CoinTossing extends JApplet implements ActionListener { int tailNumber=0,headNumber=0; JLabel TossLable,Tail

10月25日蚕豆网不推荐的Android应用:盗版《Coin Dozer》

前言:如雨后春笋般杂乱滋生的Android app遍布于网络中.下载平台中.用户的手机中,目前由于监管不严.开放性过大这些应用的安全性便成了当前Android手机最大问题.通讯录被复制.私人照片丢失.信息被公开等等事件的出现,其罪魁祸首当属那些存在安全隐患.内藏恶意代码的Android手机应用.鉴于此情况, 蚕豆网联合<安全管家>定 期为大家审查Android应用的安全性,尽我们最大力量来帮助用户来认清app.选择app,把最安全.最稳定的Android环境奉献给广大用户.应用名称:Coin

Apple Store福利 货币转换器Smart Coin

[TechWeb报道]Apple Store 也有福利哦,这次是之前限免过的货币转换器 Currency Converter.值得注意的是,软件本身并没有限免,需要按照下方的提示步骤操作,使用兑换码免费获取.本作上手简单.界面简约,除货币转换没有多余功能.支持至少175个国家货币,可以同时显示四种国币的转换,拥有非常多的汇率更新点可选.在数字按键区做放大缩小手势时,可改变显示数字大小.并且支持中文.首先,下载官方应用:Apple Store第二步,在首页下方找到软件图标(绿色的).进入之后,点击

STORED PROCEDURES: GOOD OR BAD(存储过程:好还是坏)

存储过程 Author Date Of Submission User Level Saikalyan Prasad Rao 07/06/2004 Intermediate 作者 提交日期 用户级别 Saikalyan Prasad Rao 07/06/2004 中级   I am sure this issue has been taken up and discussed in lots of articles on the net. This article aims to look at

PS制作一枚银币

引言: Photoshop 总能不断地给我们带来惊喜!我从来没有想到一个灰色的圆形图案,被加入一些杂点,稍微做点光影,就成了一枚逼真的银币!如果您有兴趣读完下面的教程,我们就可以发行专属于自己的银币了!   新建一个 RGB 颜色模式的 PSD 文档,尺寸暂定为 300 * 300 Pixels .建议使用文件名为 Silver Coin.psd .     按住工具箱中的 Rectangular Marquee Tool ( M ) 工具不放,在弹出的工具列表中选择 Elliptical Ma

[翻译]PHP安全小建议(上)

近日比较关注PHP的安全问题,国内的许多开发者,特别是PHP初学者,很多时候仅满足功能是否实现,对安全的探讨浅尝辄止甚至漠不关心.这样的后果很严重,比如泛滥的SQL注入,甚至还有直接被下载数据库连接文件的--此文译自Cal Evans发表DevZone的系列专题:PHP Security Tip (安全建议/小窍门) 虽然不是最新文章,但提到的许多原则性的东西和经典的做法仍然是值得重视的,绝对是值得一读的好文章,借此抛砖引玉,希望能给大家一点帮助,建立良好的安全意识,了解必要的防范措施. 文中加