UVA&&POJ discrete probability exercise [3]

Source: Internet
Author: User

POJ3869 headshot

Test instructions: Give the revolver bullet sequence, hit a gun no bullets, to make the next shot is not the maximum probability should rotate or shoot

Conditional probability, |00|/(|00|+|01|) And |0|/n who the big question

|00|+|01|=|0|

Note that the sequence is a ring

////main.cpp//poj3869////Created by Candy on 25/10/2016.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;Const intn= the;intn,a,b;CharS[n];intMainintargcConst Char*argv[]) {scanf ("%s", s+1); N=strlen (s+1);  for(intI=1; i<=n;i++){        if(s[i]=='0') b++; if(s[i]=='0'&&s[i+1]=='0') a++; }    if(s[n]=='0'&&s[1]=='0') a++; if(a*n>b*b) printf ("SHOOT"); Else if(a*n==b*b) printf ("EQUAL"); Elseprintf"ROTATE"); return 0;}

UVA-10491

Cows and Cars

Classic problem, a cow, b car, C door Show

Full probability formula, divided into the first selected cattle A/(A+B) and the first selected car B/(a+b) two parts

Part of the always change the door to get the car probabilities are b/(a+b-c-1) and (b-1)/...

 #include <cstdio>double   A,b,c;  int  Main (int  argc, const  char  * argv[]) { while  (scanf ( %lf%lf%lf   ", &a,&b,&c)!=eof) printf (  " %.5f\n  , (a*b+b* (B-1 ))/((a+b) * (A+b-c-1   return  0  ;}  

uva-11181probability| Given

Test instructions: N person, buy things probability pi, have r personal buy something, ask everyone actually buy things probability

Conditional probabilities

E for R personal buy things, ei for R personally I buy something

P (ei| e) =p (EiE)/P (E)

Calculate probability with Dfs pop-up everyone buy or not buy

PS: Do not read into optimization, floating point number

////main.cpp//uva11181////Created by Candy on 25/10/2016.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;Const intn= -; typedefLong LongLl;inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intN,r,vis[n];DoubleP[n],pe[n];voidDfsintDintCntDoubleProb) {//printf ("Dfs%d%d%f\n", d,cnt,prob);    if(cnt>r| | D-1-CNT&GT;N-R)return; if(d==n+1){        if(cnt==R) for(intI=1; i<=n;i++)if(Vis[i]) pe[i]+=prob; pe[0]+=prob; return; } Vis[d]=1; DFS (d+1, cnt+1, prob*P[d]); VIS[D]=0; DFS (d+1, cnt,prob* (1-p[d]));}intMainintargcConst Char*argv[]) {    intcas=0;  while((N=read ())) {printf ("Case %d:\n",++CAs); R=read ();  for(intI=1; i<=n;i++) scanf ("%LF",&P[i]); memset (Vis,0,sizeof(VIS)); memset (PE,0,sizeof(PE)); DFS (1,0,1.0);  for(intI=1; i<=n;i++) printf ("%.6f\n", pe[i]/pe[0]); }        return 0;}

UVA&&POJ discrete probability exercise [3]

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.