uva 1636 Headshot

时间:2024-01-18 22:38:14

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

首先在手枪里随机装一些子弹,然后抠了一枪,发现没有子弹。你希望下一枪也没有子
弹,是应该直接再抠一枪(输出SHOOT)呢,还是随机转一下再抠(输出ROTATE)?如果
两种策略下没有子弹的概率相等,输出EQUAL。

手枪里的子弹可以看成一个环形序列,开枪一次以后对准下一个位置。例如,子弹序列
为0011时,第一次开枪前一定在位置1或2(因为第一枪没有子弹),因此开枪之后位于位置
2或3。如果此时开枪,有一半的概率没有子弹。序列长度为2~100

抠一枪接着打:00  的概率=00的概率/00+01的概率=00的概率/0的概率

转一下再打:0 的概率/长度

防止精度误差,可以通分

#include<cstdio>
#include<cstring>
using namespace std;
char s[101];
int len,sum0,sum00;
int shoot,rotate;
int main()
{
while(scanf("%s",s)!=EOF)
{
len=strlen(s);
sum0=sum00=0;
s[len]=s[0];
for(int i=0;i<len;i++)
{
if(s[i]=='0') sum0++;
if(s[i]=='0'&&s[i+1]=='0') sum00++;
}
shoot=sum00*len;
rotate=sum0*sum0;
if(shoot>rotate) printf("SHOOT\n");
else if(rotate>shoot) printf("ROTATE\n");
else printf("EQUAL\n");
}
}