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
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. }

目录
相关文章
|
4月前
|
机器学习/深度学习 人工智能
【CatBoost报错解决】CatBoostError: Bad value for num feature[non default doc idx=0,feature idx=19]=
【CatBoost报错解决】CatBoostError: Bad value for num feature[non default doc idx=0,feature idx=19]=
|
7月前
|
C++
hdoj 4288coder & cf 85d Sum of Medians
这两个题目是一样的,大概题意是有3个操作 add x, 在集合中加入x, del x 是删除x, sum 是求出由小到大排序后所有下标mod5等于3的数的和。
16 0
|
8月前
CF489C Given Length and Sum of Digits
CF489C Given Length and Sum of Digits
|
8月前
POJ 2785 4 Values whose Sum is 0
POJ 2785 4 Values whose Sum is 0
R语言sign.test=function(x,p,q0)
这种用法的函数定义 sign.test=function(x,p,q0) 是自定义符号检验的函数,其中参数的含义如下: • x: 一个数值型向量,表示样本观测值。 • p: 一个数值,表示要检验的中位数。默认值为 0。 • q0: 一个数值,表示显著性水平(即拒绝域),默认值为 0.05。 下面是一个基于这个函数定义的例子:
257 0
|
JSON 数据格式
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
431 0
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
TestRange.cs error CS0104: `Range' is an ambiguous reference between `System.Range' and Gtk.Range
TestRange.cs error CS0104: `Range' is an ambiguous reference between `System.Range' and Gtk.Range
139 0
LeetCode 322. Coin Change
给定不同面额的硬币 coins 和一个总金额 amount。编写一个函数来计算可以凑成总金额所需的最少的硬币个数。如果没有任何一种硬币组合能组成总金额,返回 -1。
57 0
LeetCode 322. Coin Change
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
|
人工智能
Rem of Sum is Num——UPC
题目描述 Given are a sequence of N positive integers A1,A2,…,AN, and a positive integer K. Find the number of non-empty contiguous subsequences in A such that the remainder when dividing the sum of its elements by K is equal to the number of its elements.
93 0