NYOJ-ACM-Coin 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

思路:

这道题就是求硬币在正面,反面和立起来的概率。当有一个硬币立起来就输出Bingo,当硬币的right的概率减去0.5的结果大于0.003的时候就输出Fail。否则输出硬币right的概率,以最简分数的形式输出。

代码:

#include<stdio.h>
#include<math.h>
int m(int a,int b){//求最小值 
	if(a>=b){
		a = b;
	}
	return a;
}
int yueshu(int a,int b){//求最大公约数 
	int i,count = 1;
	for(i=2;i<=m(a,b);i++){
		if(a%i == 0&&b%i == 0){
			count = i;
		}
	}
	return count;
} 
int main(){
	int n,i,countu = 0,countd = 0,counts = 0;
	scanf("%d",&n);
	char a[n];
	for(i=0;i<=n;i++){
		scanf("%c",&a[i]);
		if(a[i] == 'U'){
			countu ++;
		}else if(a[i] == 'S'){
			counts++;
		}
	}
	double f= ((double)(countu)/n);//求right的概率 
	if(counts!=0){//判断输出。 
		printf("Bingo\n");
	}else if(fabs(f-0.5)>0.003){
		printf("Fail\n");
	}else{
		printf("%d/%d\n",countu/yueshu(countu,n),n/yueshu(countu,n));
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值