Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define ld double
- #define oo 1234567890
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//theres also mt19937_64 for 64 bit random integers
- int rollDice(int mn, int mx)
- {
- return uniform_int_distribution<int>(mn, mx)(rng);
- }
- int noise(int bit)
- {
- int dice1 = rollDice(0,9);
- int dice2 = rollDice(0,9);
- int dice3 = rollDice(0,9);
- return 100*(dice1<3 ? !bit : bit) + 10*(dice2<3 ? !bit : bit) + (dice2<3 ? !bit : bit);
- }
- ld MonteCarlo(int rep)
- {
- int one = 0, zero = 0;
- while(rep--)
- {
- int dice = rollDice(0,9);
- int send = (dice < 3 ? 1 : 0);
- int rec = noise(send);
- if(rec==11)
- {
- if(send)one++;
- else zero++;
- }
- }
- cout<<"Kiek kartu pasirode 011: "<<(one+zero)<<"\n";
- cout<<"Kiek kartu is ju siuntem 1: "<<one<<"\n";
- return 1.0*one/(one+zero);
- }
- int main()
- {
- ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- ld p0 = 0.7;
- ld fail = 0.3;
- //P(1 | 011) = P(011 | 1) * P(1) / P(011)
- ld magicNumber = 1./8;
- ld magicNumber2 = p0*(fail*fail*(1-fail)) + (1-p0)*fail*(1-fail)*(1-fail);
- ld res1 = fail*(1-fail)*(1-fail)*(1-p0) / (magicNumber);
- ld res2 = fail*(1-fail)*(1-fail)*(1-p0) / (magicNumber2);
- cout<<setprecision(3)<<fixed<<res1<<" "<<res2<<"\n";
- cout<<"Actual answer (with HP): "<<MonteCarlo(100000000)<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement