UVA 1636 Headshot 概率


Headshot

Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

Submit Status

Description

You have a revolver gun with a cylinder that has n chambers. Chambers are located in a circle on a cylinder. Each chamber can be empty or can contain a round. One chamber is aligned with the gun‘s barrel. When
trigger of the gun is pulled, the gun‘s cylinder rotates, aligning the next chamber with the barrel, hammer strikes the round, making a shot by firing a bullet through the barrel. If the chamber is empty when the hammer strikes it, then there is no shot but
just a ``click".

You have found a use for this gun. You are playing Russian Roulette with your friend. Your friend loads rounds into some chambers, randomly rotates the cylinder, aligning a random chamber with a gun‘s barrel,
puts the gun to his head and pulls the trigger. You hear ``click" and nothing else -- the chamber was empty and the gun did not shoot.

Now it is your turn to put the gun to your head and pull the trigger. You have a choice. You can either pull the trigger right away or you can randomly rotate the gun‘s cylinder and then pull the trigger. What
should you choose to maximize the chances of your survival?

Input

The input file contains several datasets. A dataset contains a single line with a string of n digits `` 0" and `` 1" ( 2n100).
This line of digits represents the pattern of rounds that were loaded into the gun‘s chambers. `` 0" represent an empty chamber, `` 1" represent a loaded one. In this representation, when cylinder rotates before a shot, the next chamber to
the right gets aligned with the barrel for a shot. Since the chambers are actually located on a circle, the first chamber in this string follows the last one. There is at least one `` 0" in this string.

Output

For each dataset, write to the output file one of the following words (without quotes):

  • ``SHOOT" -- if pulling the trigger right away makes you less likely to be actually shot in the head with the bullet (more likely that the chamber will be empty).
  • ``ROTATE" -- if randomly rotating the cylinder before pulling the trigger makes you less likely to be actually shot in the head with the bullet (more likely that the chamber will be empty).
  • ``EQUAL" -- if both of the above choices are equal in terms of probability of being shot.

Sample Input

0011
0111
000111

Sample Output

EQUAL
ROTATE
SHOOT

Source

Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 10. Maths :: Examples

Submit Status

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

string gun;

int main()
{
    while(cin>>gun)
    {
        int sz=gun.size();
        int o1=0,t1=0,o2=0,t2=0;
        for(int i=0;i<sz;i++)
        {
            if(gun[i]=='0')
            {
                o1++;
                if(gun[(i+1)%sz]=='0') o2++;
                else t2++;
            }
            else t1++;
        }
        int p1=o1*(o2+t2);
        int p2=o2*(o1+t1);
        if(p1==p2) puts("EQUAL");
        else if(p1<p2) puts("SHOOT");
        else puts("ROTATE");
    }
    return 0;
}
时间: 2024-10-26 16:37:48

UVA 1636 Headshot 概率的相关文章

uva 1636 - Headshot(简单概率问题)

直接扣一枪没有子弹 是条件概率 转一下再扣一枪 是简单事件发生的概率 前者用00的个数除以00和01子串的总数 后者用0的个数除以所有数字的个数 然后换算一下运算方式比较即可 #include<cstdio> #include<cstring> const int maxn = 105; char s[105]; int cnt0,cnt1,cnt2,cnt3; int main() { while(scanf("%s",s+1)!=EOF) { cnt0=0;

UVa 1636 - Headshot(概率)

链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4511 题意: 首先在手枪里随机装一些子弹,然后抠了一枪,发现没有子弹.你希望下一枪也没有子弹,是应该直接再抠一枪(输出SHOOT)呢,还是随机转一下到任意位置再抠(输出ROTATE)?如果两种策略下没有子弹的概率相等,输出EQUAL.手枪里的子弹可以看成一个环形序列,开枪一次以后对

uva 1636 Headshot

https://vjudge.net/problem/UVA-1636 首先在手枪里随机装一些子弹,然后抠了一枪,发现没有子弹.你希望下一枪也没有子弹,是应该直接再抠一枪(输出SHOOT)呢,还是随机转一下再抠(输出ROTATE)?如果两种策略下没有子弹的概率相等,输出EQUAL. 手枪里的子弹可以看成一个环形序列,开枪一次以后对准下一个位置.例如,子弹序列为0011时,第一次开枪前一定在位置1或2(因为第一枪没有子弹),因此开枪之后位于位置2或3.如果此时开枪,有一半的概率没有子弹.序列长度为

UVA 11021 - Tribles(概率递推)

UVA 11021 - Tribles 题目链接 题意:k个毛球,每个毛球死后会产生i个毛球的概率为pi,问m天后,所有毛球都死亡的概率 思路:f[i]为一个毛球第i天死亡的概率,那么 f(i)=p0+p1f(i?1)+p2f(i?1)2+...+pnf(i?1)n 然后k个毛球利用乘法定理,答案为f(m)k 代码: #include <stdio.h> #include <string.h> #include <math.h> const int N = 1005;

UVA 10288 - Coupons(概率递推)

UVA 10288 - Coupons 题目链接 题意:n个张票,每张票取到概率等价,问连续取一定次数后,拥有所有的票的期望 思路:递推,f[i]表示还差i张票的时候期望,那么递推式为 f(i)=f(i)?(n?i)/n+f(i?1)?i/n+1 化简后递推即可,输出要输出分数比较麻烦 代码: #include <cstdio> #include <cstring> #include <cmath> long long gcd(long long a, long lon

UVA 11291 - Smeech(概率+词法分析)

UVA 11291 - Smeech 题目链接 题意:给定一个表达式形如e=(p,e1,e2) 该表达式的值为 p?(e1+e2)+(1?p)?(e1?e2),求出值 思路:题目是很水,但是处理起来还挺麻烦的,模拟写编译器LEX分析器原理去写了. 代码: #include <cstdio> #include <cstring> const int N = 100005; char str[N]; int now, len, token; double value; void get

UVA 11346 - Probability(概率)

UVA 11346 - Probability 题目链接 题意:给定a,b,s要求在[-a,a]选定x,在[-b,b]选定y,使得(0, 0)和(x, y)组成的矩形面积大于s,求概率 思路:这样其实就是求xy > s的概率,那么画出图形,只要求y = s / x的原函数, y = slnx,带入两点相减就能求出面积,面积比去总面积就是概率 代码: #include <cstdio> #include <cstring> #include <cmath> int

uva 10288 - Coupons(概率)

题目链接:uva 10288 - Coupons 题目大意:给定n,为有n中兑换卷,现在每开一次箱子,就能等概率的获得其中的一种兑换卷.问说平均情况下需要开多少个箱子才能集齐n种兑换卷. 解题思路:dp[i]表示还有i种没获得,dp[i]=n?in?dp[i]+in?dp[i?1]+1 ===>dp[i]=dp[i?1]+ni #include <cstdio> #include <cstring> #include <algorithm> using names

UVA 11971 - Polygon(概率+几何概型)

UVA 11971 - Polygon 题目链接 题意:给一条长为n的线段,要选k个点,分成k + 1段,问这k + 1段能组成k + 1边形的概率 思路:对于n边形而言,n - 1条边的和要大于另外那条边,然后先考虑3边和4边形的情况,根据公式在坐标系中画出来的图,总面积为x,而不满足的面积被分成几块,每块面积为x/2k,然后在观察发现一共是k + 1块,所以符合的面积为x?x?(k+1)/2k,这样一来除以总面积就得到了概率1?(k+1)/2k 代码: #include <cstdio>