UVa 1636 (probability) headshot

Source: Internet
Author: User

Since it is the first probability problem, serious to analyze it.

Test instructions

There is a revolver, which is randomly loaded or not loaded, and is represented by a 01 sequence. Now known to pull the first trigger without bullets, asked whether to continue to pull the trigger or random rotation of the buckle, that choice makes the second pull the trigger is not the probability of a bullet.

Analysis:

This is a conditional probability that the first time the trigger is known to be pulled without bullets.

Set the sequence length to n,00 sequence number of a,0 is the number of B

Then the second time if there is no bullet, it corresponds to the given sequence of two consecutive 0, the sample space is B, so the probability is a/b

If a random rotation, the first buckle and the second time is completely independent, so the probability is b/n

1#include <cstdio>2#include <cstring>3 4 Const intMAXN = -+Ten;5 CharS[MAXN];6 7 intMain ()8 {9     //freopen ("In.txt", "R", stdin);Ten  One      while(SCANF ("%s", s) = =1) A     { -         intL =strlen (s); -S[L] = s[0]; the         intZero =0, Doublezero =0; -          for(inti =0; I < L; ++i) -         { -             if(S[i] = ='0') +zero++; -             if(S[i] = ='0'&& s[i+1] =='0') +doublezero++; A         } at         intD = Doublezero * L-zero *Zero; -         if(D >0) -Puts"SHOOT"); -         Else if(D <0) -Puts"ROTATE"); -         Else inPuts"EQUAL"); -     } to  +     return 0; -}
code June

UVa 1636 (probability) headshot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.