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
 1 import java.text.NumberFormat;
 2 import java.util.Arrays;
 3 import java.util.Scanner;
 4
 5 public class Main {
 6     public static void main(String[] args) {
 7         Scanner scanner=new Scanner(System.in);
 8         char s[]=new char[65536];
 9         int number;
10         int i;
11         int count;
12         double chu;
13         int flag=0;
14
15         number=scanner.nextInt();
16         s=scanner.next().toCharArray();
17
18         count=0;
19         for(i=0;i<s.length;i++){
20             if(s[i]==‘U‘)
21                 count++;
22
23             else if(s[i]==‘S‘)
24                 flag=1;
25         }
26
27         chu=count*1.0/number;
28
29         if(Math.abs(chu-0.5)<=0.003){
30             System.out.println(count/gcd(count,number)+"/"+number/gcd(count,number));
31
32         }
33         else{
34             if(flag==1)
35                 System.out.println("Bingo");
36
37             else
38                 System.out.println("Fail");
39         }
40     }
41
42     static int gcd(int a,int b){
43         int temp;
44
45         if(a<b){
46             temp=a;
47             a=b;
48             b=temp;
49         }
50
51         while(a%b!=0){
52             temp=a%b;
53             a=b;
54             b=temp;
55         }
56         return b;
57     }
58 }
 
时间: 2024-08-14 16:27:28

Coin Test的相关文章

NYOJ 698 A Coin Problem (斐波那契)

链接:click here 题意: 描述 One day,Jiameier is tidying up the room,and find some coins. Then she throws the coin to play.Suddenly,she thinks of a problem ,that if throw n times coin ,how many situations of no-continuous up of the coin. Hey,Let's solve the

Learn Python 016: Coin - a project of msc, unfinished.

import random class Coin: def __init__(self, rare=False, clean=True, **kwargs): for key,value in kwargs.items(): setattr(self,key,value) self.is_rare = rare self.is_clean = clean self.heads = heads if self.is_rare: self.value = self.original_value *

dp背包问题/01背包,完全背包,多重背包,/coin change算法求花硬币的种类数

一步一步循序渐进. Coin Change 具体思想:给你 N元,然后你有几种零钱S={S1,S2...,Sm} (每种零钱数量不限). 问:凑成N有多少种组合方式  即N=x1 * S1+x2*S2+...+xk*Sk (xk>=0,k=1,2..m) 设有f(x)中组合方式 有两种解答(自底向上回溯): 1.不用第m种货币   f(N,m-1) 2.用第m种货币 f(N-Sm,m) 总的组合方式为f(N,m)=f(N,m-1)+f(N-Sm,m) anything is nonsense,s

[LeetCode] Coin Change

You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins,

[LeetCode][JavaScript]Coin Change

Coin Change You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination o

Project Euler 78:Coin partitions

Coin partitions Let p(n) represent the number of different ways in which n coins can be separated into piles. For example, five coins can separated into piles in exactly seven different ways, so p(5)=7. OOOOOOOOO OOOO OOOOO O OOO OO OOO O O OO O O O

UVA 674 Coin Change

DP,背包的思想. 问 最多7489块钱.有多少种组成方式.面额分别为 1,5,10,25,50: 由于不限制硬币数量,所以完全背包,累加就可以了. #include<cstdio> #include<cstring> #include<string> #include<queue> #include<algorithm> #include<map> #include<stack> #include<iostream

ACM-对称博弈之Coin Game——hdu3951

Coin Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1145    Accepted Submission(s): 668 Problem Description After hh has learned how to play Nim game, he begins to try another coin game w

[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 called Xoinc for them. Initially a stack of N (5 <= N <= 2,000) coins sits on the ground; coin i from the top has integer value C_i (1 <= C_i <=

1235 - Coin Change (IV)

   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given n coins, values of them are A1, A2 ... An respectively, you have to find whether you can pay K using the coins. You can use any coin at most two times. Input Input st