UVa 1636 决斗

https://vjudge.net/problem/UVA-1636

题意:

首先在手枪里随机装了一些子弹,然后抠了一枪,发现没有子弹。你希望下一枪也没有子弹,是应该直接再抠一枪还是随机转一下再抠。

 

思路:

第一个是一个条件概率,再抠一枪没有子弹的概率是建立在前者已发生的情况下,利用公式,统计00和0的个数就可以计算出P(A|B)的值。

第二个是简单事件发生概率,直接计算出0的比率即可。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<string>
 6 using namespace std;
 7 
 8 const int maxn=100+5;
 9 
10 char str[maxn];
11 
12 int main()
13 {
14     //freopen("D:\\input.txt","r",stdin);
15     while(gets(str))
16     {
17         int a=0,b=0;
18         int len=strlen(str);
19         for(int i=0;i<len;i++)
20         {
21             if(str[i]=='0' && str[(i+1)%len]=='0')  a++;
22             if(str[i]=='0')   b++;
23         }
24         if(a*len==b*b)  printf("EQUAL\n");
25         else if(a*len>b*b)  printf("SHOOT\n");
26         else printf("ROTATE\n");
27     }
28     return 0;
29 }

 

posted @ 2017-04-08 17:30  Kayden_Cheung  阅读(172)  评论(0编辑  收藏  举报
//目录