NYOJ---题目204Coin Test

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<stdio.h>
#include<math.h>
using namespace std;
char a[65550];
int gcd(int a,int b)
{
   if(b==0) return a;
   return gcd(b,a%b);
}
int main()
{
    int n;
    char c='/';
    while(cin>>n)
    {
       for(int i=0;i<n;i++)
            cin>>a[i];
        int t1,t2,t3;
        t1=0,t2=0,t3=0;
       for(int i=0;i<n;i++)
       {
           if(a[i]=='U')
            t1++;
           else if(a[i]=='D')
            t2++;
           else if(a[i]=='S')
            t3++;
       }
       if(t3)
        printf("Bingo\n");
        else if(fabs(t1-t2)>3)
            printf("Fail\n");
        else
            printf("%d%c%d\n",(t1/gcd(t1,n)),c,(n/gcd(t1,n)));

    }
    return 0;
}
时间: 2024-11-06 12:14:56

NYOJ---题目204Coin Test的相关文章

NYOJ题目57 6174问题

----------------------------------------------------- 感觉这个OJ题目难度划分很不合理,这道理明明很简单却给了2的难度,而之前难度为0的水题有好多难死个人没做出来让我暗暗觉得自己脑子里都是屎... 把题目描述翻译成人话的意思就是多少次以后这个序列会出现,想明白这一点就比较简单了. AC代码: 1 import java.util.Arrays; 2 import java.util.Scanner; 3 4 public class Main

NYOJ题目1049自增自减

--------------------------------- 简单的字符判断. AC代码: 1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 7 Scanner sc=new Scanner(System.in); 8 9 int times=Integer.parseInt(sc.nextLine()); 10 while(times-->0

NYOJ题目10505C?5S?

--------------------------------------- 水. AC代码: 1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 7 Scanner sc=new Scanner(System.in); 8 9 int times=sc.nextInt(); 10 while(times-->0){ 11 double a=sc.n

NYOJ 题目56 阶乘式因式分解(一)

题目描述: 给定两个数m,n,其中m是一个素数. 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m. 输入 第一行是一个整数s(0<s<=100),表示测试数据的组数随后的s行, 每行有两个整数n,m. 输出 输出m的个数. 样例输入 2 100 5 16 2 样例输出 24 15我的代码://AC #include<stdio.h>int main(){ int s,k; scanf("%d",&s); while(s--)

NYOJ题目28大数阶乘

-------------------------------------祭出BigInteger AC代码: import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); BigInteger ans=fac(n);

NYOJ题目124中位数

------------------------------------- 排序取中间数即可 AC代码: 1 import java.util.Arrays; 2 import java.util.Scanner; 3 4 public class Main { 5 6 public static void main(String[] args) { 7 8 Scanner sc=new Scanner(System.in); 9 10 int times=sc.nextInt(); 11 wh

NYOJ题目168房间安排

------------------------------------------------ 其实就是计算一下时间线上重叠部分的最大值是多少 一个很容易想到的办法就是模拟,如下 AC代码: 1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 7 Scanner sc=new Scanner(System.in); 8 9 int times=sc.

NYOJ题目125盗梦空间

----------------------------------------- 开始的时候打算每进入或退出一层就换算成那层的时间,然而WA了. 怒,干脆就来点暴力的,管你什么跟什么只要停留了就根据层次统一换算成现实时间,使用BigDecimal保证精度,AC. AC代码: 1 import java.math.BigDecimal; 2 import java.util.Scanner; 3 4 public class Main { 5 6 public static void main(

NYOJ题目114某种序列

----------------------------------------- 迭代相加即可 AC代码: 1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 public class Main { 5 6 public static void main(String[] args) { 7 8 Scanner sc=new Scanner(System.in); 9 10 while(sc.hasNextBigInte

NYOJ题目74小学生算术

-------------------------------- 模拟加法过程即可. AC代码: 1 import java.io.BufferedReader; 2 import java.io.IOException; 3 import java.io.InputStreamReader; 4 5 public class Main { 6 7 public static void main(String[] args) throws NumberFormatException, IOExc