ACM Coin Test
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"
- 样例输入
-
6
UUUDDD - 样例输出
-
1/2
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std; int gcd(int a, int b){
if( a < b) swap(a,b);
while(b){
int t = b;
b = a%b;
a = t;
}
return a;
} int main(){
int n ;
cin >> n;
int uCnt = ;
for(int i = ; i < n ; ++ i){
char ch;
cin >> ch;
if(ch == 'U') uCnt++;
else if(ch == 'S'){
cout<< "Bingo"<<endl;
return ;
}
}
double pssiblity = double(uCnt)/n;
if(fabs(pssiblity - 0.5) > 0.003) cout<<"Fail"<<endl;
else cout<<uCnt/gcd(uCnt,n)<<"/"<<n/gcd(uCnt,n)<<endl;
}
ACM Coin Test的更多相关文章
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 【转载】ACM总结——dp专辑
感谢博主—— http://blog.csdn.net/cc_again?viewmode=list ---------- Accagain 2014年5月15日 动态规划一 ...
- UVA 674 Coin Change(dp)
UVA 674 Coin Change 解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...
- 【DP专辑】ACM动态规划总结
转载请注明出处,谢谢. http://blog.csdn.net/cc_again?viewmode=list ---------- Accagain 2014年5月15日 ...
- ACM STUDY
ACM学习<二> 穷举算法思想: 一句话:就是从所有可能的情况,搜索出正确的答案. 步骤: 1.对于一种可能的情况,计算其结果. 2.判断结果是否满足,YES计 ...
- ACM Piggy Bank
Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...
- [HDOJ]Coin Change(DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2069 题意 有面值1,5,10,25,50的硬币数枚,对于输入的面值n,输出可凑成面值n(且限制总硬笔 ...
- HDU 3420 -- Bus Fair ACM
Bus Fair Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- ACM 第十二天
博弈论(巴什博奕,威佐夫博弈,尼姆博弈,斐波那契博弈,SG函数,SG定理) 一. 巴什博奕(Bash Game): A和B一块报数,每人每次报最少1个,最多报4个,看谁先报到30.这应该是最古老的关 ...
随机推荐
- lsof -ntP -i:端口取出 动行程序的PID 然后xargs kill -9 这个进程
[root@ok ok]# lsof -ntP -i: [root@ok ok]# netstat -lnutp|grep tcp /dnsmasq tcp /sshd tcp ::: :::* LI ...
- SQL中的JOIN类型解释(CROSS, INNER,OUTER),关键字ON,USING
书上讲得明白,解了不少迷惑. SELECT e.fname, e.lname, d.name FROM employee AS e INNER JOIN department AS d ON e.de ...
- ArcGIS ElementLayer上放置Windows控件
ElementLayer是ArcGIS API for Silverlight/WPF中的一种图层类型,主要用来承载Silverlight/WPF中的UIElement对象(UIElement),使用 ...
- java 杂物间 (二) Spring Web
需要明确记住的继承关系
- android 入门-git之上传本地代码到github
github部分: 1.首先去github网站 上注册一个用户 2.说明 https://guides.github.com/activities/hello-world/ 2.点击 New repo ...
- C语言中结构体的位域(bit-fields)
转自:http://blog.sina.com.cn/s/blog_6240b5980100tcba.html 有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位.例如在存放一 ...
- [Java] arraycopy 数组复制(转)
public class ArraycopyTest { public static void main(String[] args) { //静态初始化两个长度不同的 ...
- ArrayList集合&特殊集合
一.ArrayList集合 集合内可以放不同类型的元素 另:object类型为所有数据类型的基类 添加元素:.add(); 清空集合:al.clear(); 克隆集合:.clone(); 判断是否包含 ...
- Hibernate的持久化类状态
Hibernate的持久化类状态 持久化类:就是一个实体类 与 数据库表建立了映射. Hibernate为了方便管理持久化类,将持久化类分成了三种状态. 瞬时态 transient (临时态):持久化 ...
- CentOS下Redis安装配置小结
Redis是REmote DIctionary Server的缩写. 是一个使用 C 语言写成的,开源的 key-value 非关系型数据库.跟memcached类似,不过数据可以持久化. Redis ...