您的位置:首页 > 其它

例10-9 uva1636简单概率问题

2015-10-11 20:38 441 查看
题意:一个01串,0代表没子弹,1代表有子弹。在开一次空枪后,开下一枪没子弹概率大的方案

①接着开枪 ②随机转一下再开枪

思路:

在情况一就是求00在0中占的比例,情况二则是0在整个串中的比例

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
typedef long long ll;
using namespace std;

const int maxn = 105;
char p[maxn];
int main()
{
while(scanf("%s",p) != EOF)
{
int len =strlen(p);
int anum = 0;
int tnum;
p[len] = p[0];
for(int i = 0; i < len; i++)
{
if(p[i] == '0')
anum++;
}
double rotat = (double)anum / len;
tnum = 0;
for(int i = 0; i < len; i++)
{
if(p[i] == '0' && p[i+1] == '0')
tnum ++;
}
double shoot = (double)tnum/anum;
if(shoot > rotat)
printf("SHOOT\n");
else if(shoot < rotat)
printf("ROTATE\n");
else
printf("EQUAL\n");
}
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: