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
#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的更多相关文章

  1. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  2. 【转载】ACM总结——dp专辑

    感谢博主——      http://blog.csdn.net/cc_again?viewmode=list       ----------  Accagain  2014年5月15日 动态规划一 ...

  3. UVA 674 Coin Change(dp)

    UVA 674  Coin Change  解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...

  4. 【DP专辑】ACM动态规划总结

    转载请注明出处,谢谢.   http://blog.csdn.net/cc_again?viewmode=list          ----------  Accagain  2014年5月15日 ...

  5. ACM STUDY

    ACM学习<二>   穷举算法思想:     一句话:就是从所有可能的情况,搜索出正确的答案. 步骤:     1.对于一种可能的情况,计算其结果.     2.判断结果是否满足,YES计 ...

  6. ACM Piggy Bank

    Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...

  7. [HDOJ]Coin Change(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2069 题意 有面值1,5,10,25,50的硬币数枚,对于输入的面值n,输出可凑成面值n(且限制总硬笔 ...

  8. HDU 3420 -- Bus Fair ACM

    Bus Fair Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  9. ACM 第十二天

    博弈论(巴什博奕,威佐夫博弈,尼姆博弈,斐波那契博弈,SG函数,SG定理) 一.  巴什博奕(Bash Game): A和B一块报数,每人每次报最少1个,最多报4个,看谁先报到30.这应该是最古老的关 ...

随机推荐

  1. Java 内存区域和GC机制

    目录 Java垃圾回收概况 Java内存区域 Java对象的访问方式 Java内存分配机制 Java GC机制 垃圾收集器 Java垃圾回收概况 Java GC(Garbage Collection, ...

  2. EasyUi – 2.布局Layout + 3.登录界面

    1.页面布局 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.a ...

  3. 11.外观模式(Facade Pattern)

    using System; namespace ConsoleApplication4 { class Program { /// <summary> /// 不使用外观模式的情况 /// ...

  4. Easy UI 面板

    驾考园 http://www.jiakaoyuan.com 驾考园信息网 下载(源码)

  5. Ubuntu下安装Python3.4

    转自:http://blog.sina.com.cn/s/blog_7cdaf8b60102vf2b.html 1. 通过命令行安装Python3.4,执行命令:sudo apt-get instal ...

  6. C语言中do...while(0)的妙用

    在linux内核代码中,经常看到do...while(0)的宏,do...while(0)有很多作用,下面举出几个: 1.避免goto语句: 通常,如果一个函数开始要分配一些资源,然后如果在中途遇到错 ...

  7. 终于看完<LEARNING SQL>第二版,立此存照

  8. OCJP(1Z0-851) 模拟题分析(九)over

    Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有 ...

  9. 算法系列:Reservoir Sampling

    copyright © 1900-2016, NORYES, All Rights Reserved. http://www.cnblogs.com/noryes/ 欢迎转载,请保留此版权声明. -- ...

  10. 攻城狮在路上(叁)Linux(二十四)--- linux设置开机挂载及镜像文件挂载

    虽然可以手动进行文件系统的挂载,但是每次都手动挂载就会很麻烦,开机挂载的目的就是实现文件系统的自动挂载. 一.开机挂载:/etc/fstab及/etc/mtab 主要是通过修改/etc/fstab文件 ...