描述

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. delphi请求idhttp数据

    idhttp ss : TStringStream; begin ss := TStringStream.)); { 指定gb2312的中文代码页,或者54936(gb18030)更好些 utf8 对 ...

  2. 1001Sum Problem

    Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): ...

  3. SpriteKitCommonUse

    [SpriteKitCommonUse] 1.SKView中提供了显示FPS和NodeCount(当前view)的方法,如下: 展现一个scene: - (void)viewWillAppear:(B ...

  4. Java模板引擎 FreeMarker

    @(编程) [TOC] 1. 简介 FreeMarker是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯Java编写.它是为Java程序员提供的一个开发包.它不是面向最终用户的,而是为程序员 ...

  5. 个人用户安装SEP注意事项

    一.安装时选择“非管控客户端” 二.安装时选择“自定义安装” 三.不要安装“应用程序与设备控制”,否则会拖慢开机   离线病毒库下载地址 http://www.symantec.com/securit ...

  6. POJ1338Ugly Numbers(DP)

    http://poj.org/problem?id=1338 第一反应就是DP,DP[i] = min{2*DP[j], 3*DP[k], 5*DP[p] j,k,p<i};于是枚举一下0-i- ...

  7. UVaLive 6698 Sightseeing Bus Drivers (水题,贪心)

    题意:n个工人,有n件工作a,n件工作b,每个工人干一件a和一件b,a[i] ,b[i]代表工作时间,如果a[i]+b[j]>t,则老板要额外付钱a[i]+b[j]-t;现在要求老板付钱最少: ...

  8. UVa 10316 - Airline Hub

    题目:给出地球上的n个机场的经度和纬度,想在这里面确定一个HUB使得他到其他机场的最大距离最小. 分析:计算几何.大地坐标系.因为数据不大直接枚举即可,比较时利用圆心角可以提高计算效率,并控制精度. ...

  9. hdoj 5371 Hotaru's problem

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5371 这道题用到了Manacher算法,首先简单介绍一下Manacher算法: ----------- ...

  10. The_Last_Geass

    我在此立下最终的Flag,为了让它保持在第一条我不会再发任何说说:从吃晚饭开始心情就有些崩溃,感觉毫无希望.一直到现在三个多小时吧,想了很多写了很多也跑了两圈步,也许明白了些什么. 现在1月,距离省选 ...