描述

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. Hadoop MapReduce概念学习系列之mr程序组件全貌(二十)

    其实啊,spilt是,控制Apache Hadoop Mapreduce的map并发任务数,详细见http://www.cnblogs.com/zlslch/p/5713652.html map,是m ...

  2. <转>单播,广播,组播的缺点与优点

    原文链接:http://apje.blog.163.com/blog/static/145345252007101175714761/ 当前的网络中有三种通讯模式:单播.广播.组播(多播),其中的组播 ...

  3. Azure中国版 制作镜像 捕捉镜像

    因为项目需要需要部署多台功能一样的服务器,简单来说是多台nginx服务器.如果按照原始的做法,是新建vm,然后一台台部署相关服务. 现在Azrue已经可以通过捕获镜像的方式创建vm镜像模板,然后按照创 ...

  4. mvn安装jar文件到本地

    mvn install:install-file -DgroupId=com.jfinal -DartifactId=jfinal -Dversion=2.3 -Dpackaging=jar -Dfi ...

  5. [转载]关于AutoCAD.NET的辅助方法

    转载自:http://www.cnblogs.com/milian/p/3315000.html 求中点坐标: /// <summary> /// 中点 /// </summary& ...

  6. 获取父进程ID

    本程序主要功能是:获取某程序的ParentProcessID 直接上代码: // parent.cpp (Windows NT/2000) // // This example will show t ...

  7. C#中的Collection 3

    IList<T> 和 ICollection<T> 最重要的一些类型 List<T>: Encapsulates[T], like array, but also ...

  8. MES取所有部门的函数实例

    USE [ChangHong]GO/****** Object: UserDefinedFunction [dbo].[FN_GetDeptCode] Script Date: 04/26/2016 ...

  9. HTML第七天学习笔记

    今天主要是学习如何使用JS,第一个就是先是使用JS输出"Hello world" <!doctype html> <html lang="en" ...

  10. HTML第四天学习笔记

    今天老师教了下无序列表和有序列表,虽然并没有,同时做了个随堂练习: <html> <head> <title>随堂练习00</title> <me ...