描述

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
 import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Scanner; public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
char s[]=new char[65536];
int number;
int i;
int count;
double chu;
int flag=0; number=scanner.nextInt();
s=scanner.next().toCharArray(); count=0;
for(i=0;i<s.length;i++){
if(s[i]=='U')
count++; else if(s[i]=='S')
flag=1;
} chu=count*1.0/number; if(Math.abs(chu-0.5)<=0.003){
System.out.println(count/gcd(count,number)+"/"+number/gcd(count,number)); }
else{
if(flag==1)
System.out.println("Bingo"); else
System.out.println("Fail");
}
} static int gcd(int a,int b){
int temp; if(a<b){
temp=a;
a=b;
b=temp;
} while(a%b!=0){
temp=a%b;
a=b;
b=temp;
}
return b;
}
}
 

Coin Test的更多相关文章

  1. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  2. 洛谷P2964 [USACO09NOV]硬币的游戏A Coin Game

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

  3. [luogu2964][USACO09NOV][硬币的游戏A Coin Game] (博弈+动态规划)

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

  4. LeetCode Coin Change

    原题链接在这里:https://leetcode.com/problems/coin-change/ 题目: You are given coins of different denomination ...

  5. ACM Coin Test

    Coin Test 时间限制:3000 ms  |  内存限制:65535 KB 难度:1   描述 As is known to all,if you throw a coin up and let ...

  6. HDOJ 2069 Coin Change(母函数)

    Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. leetcode:Coin Change

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  8. UVa 674 Coin Change【记忆化搜索】

    题意:给出1,5,10,25,50五种硬币,再给出n,问有多少种不同的方案能够凑齐n 自己写的时候写出来方案数老是更少(用的一维的) 后来搜题解发现,要用二维的来写 http://blog.csdn. ...

  9. Epic - Coin Change

    Something cost $10.25 and the customer pays with a $20 bill, the program will print out the most eff ...

  10. UVA 674 Coin Change (DP)

    Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make c ...

随机推荐

  1. Unix 环境高级编程---线程创建、同步、

    一下代码主要实现了linux下线程创建的基本方法,这些都是使用默认属性的.以后有机会再探讨自定义属性的情况.主要是为了练习三种基本的线程同步方法:互斥.读写锁以及条件变量. #include < ...

  2. B. Rebranding

    http://codeforces.com/problemset/problem/591/B   B. Rebranding time limit per test 2 seconds memory ...

  3. 行为识别(action recognition)相关资料

    转自:http://blog.csdn.net/kezunhai/article/details/50176209 ================华丽分割线=================这部分来 ...

  4. HDU 3920Clear All of Them I(状压DP)

    HDU 3920   Clear All of Them I 题目是说有2n个敌人,现在可以发n枚炮弹,每枚炮弹可以(可以且仅可以)打两个敌人,每一枚炮弹的花费等于它所行进的距离,现在要消灭所有的敌人 ...

  5. 【转贴】Linux系统NGINX负载均衡404错误处理方法

    NGINX负载均衡404错误处理方法 使用NGINX 实现负载均衡,但一组服务器的数据不是实施同步,主服务器有了数据要过段时间才同步到其他服务器 upstream   image.stream.com ...

  6. thinkphp 定位查询 Model:last您所请求的方法不存在!

    thinkphp 定位查询 Model:last您所请求的方法不存在!   用thinkphp3.1做项目的时候为了获取记录表中最后一个id用到了last()方法,出现了这个错误:Model:last ...

  7. hdu 5407

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5407 题意:给定一个数n,求LCM(C(n,0),C(n,1),C(n,2)...,C(n,n)) 根 ...

  8. VC中常用的宏[转]

    我们在VS环境中开发的时候,会遇到很多宏定义,这些宏可以应用到代码中,或用于编译.工程选项等设置,总之是我们开发中必不可少的工具,有必要做一个总结.有些宏是C/C++定义的,有些宏是VC环境预定义的. ...

  9. strlen与sizeof的区别 [转]

    转自:http://www.cppblog.com/liangbo/archive/2006/10/06/13394.html 1.sizeof操作符的结果类型是size_t,它在头文件中typede ...

  10. java中Arrays类中,binarySearch()方法的返回值问题

    最近在复习Java知识,发现果然不经常使用忘得非常快... 看到binarySearch()方法的使用时,发现书上有点错误,于是就自己上机实验了一下,最后总结一下该方法的返回值. 总结:binaryS ...