2015 Zhejiang problem I:no2 (probability problem, Bayesian formula)

Source: Internet
Author: User

Title Link: http://acm.zjut.edu.cn/onlinejudge/problem.php?cid=1101&pid=8
Surface:

Problem I:no2 Time limit: 1 Sec Memory Limit: MB
Submit: 342 Solved: 23
[Submit] [Status] [Web Board] Description

Known to have a city of n people, the probability of having a zombie disease is p. You go to the test and check it out is positive. The doctor told you this test, the person who has the disease detects positive probability is R11, the person who does not have the disease detects positive probability is R12. Then, for the sake of insurance, the doctor gave you a better medicine to test, this is a negative, this drug disease people detected the probability of positive is r21, no disease of the person detected is positive probability R22. Excuse me, what is your probability of getting sick now?

Input

Enter N,p,r11,r12,r21,r22 per line

Output

Output probability per line, reserved 6 decimal places

Sample Input
1000 0.01 1 1 1 0
Sample Output
0.000000


The puzzle: Probability theory has been returned to the teacher, embarrassed, know that the Bayesian formula, but do not remember, and finally the imagination came out!!
Bayesian formula:
P (ai|b) =p (B|ai) p (AI)/∑ (P (B|aj) p (Aj)) = P (b|ai) p (AI)/p (B)
Conjecture: It should be similar to Bayesian.
First of all, the probability of detection of disease is X, the probability of not being ill is 1-x. Then use x instead of P, and then the second data to calculate once, that is the result.
Formula:
x=r1*p/(r1*p+ (1-p) *R2);
ans=x* (1-R3)/(x* (1-R3) + (1-x) * (1-R4));Code:
#include <iostream>  #include <cstring>  #include <cstdio>  #include <string>  #include <iomanip>  #include <vector>  #include <map>  #include <set>  # Include <algorithm>  #include <queue>  #include <cmath>  using namespace std;    int main () {     int n;     Double p,r1,r2,r3,r4,ans,x1,x2;     while (CIN>>N>>P>>R1>>R2>>R3>>R4)     {         x1=r1*p/(r1*p+ (1-p) *r2); ans= X1* (1-R3)/(X1* (1-R3) + (1-x1) * (1-R4));        Cout<<fixed<<setprecision (6) <<ans<<endl;     }     



Problem I:no2 Time limit: 1 Sec Memory Limit: MB
Submit: 342 Solved: 23
[Submit] [Status] [Web Board] Description

It is known that there is a cityNman, the probability of having a zombie disease isP. You go to the test and check it out is positive. The doctor told you this test, the probability that the sick person detected positive isR11, the probability of a positive being detected by a person who doesn't get sick isR12. Then, for the sake of insurance, the doctor gave you a better medicine to test, this time is negative, this drug disease people detect positive probability isR21, the probability that a person who doesn't get sick is tested positive.R22. excuse me, what is your probability of getting sick now ?

Input

Enter N,p,r11,r12,r21,r22 per line

Output

Output probability per line, reserved 6 decimal places

Sample Input
1000 0.01 1 1 1 0
Sample Output
0.000000

2015 Zhejiang problem I:no2 (probability problem, Bayesian formula)

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.