Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ld double
  5. #define oo 1234567890
  6.  
  7. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//theres also mt19937_64 for 64 bit random integers
  8.  
  9. int rollDice(int mn, int mx)
  10. {
  11. return uniform_int_distribution<int>(mn, mx)(rng);
  12. }
  13.  
  14. int noise(int bit)
  15. {
  16. int dice1 = rollDice(0,9);
  17. int dice2 = rollDice(0,9);
  18. int dice3 = rollDice(0,9);
  19.  
  20. return 100*(dice1<3 ? !bit : bit) + 10*(dice2<3 ? !bit : bit) + (dice2<3 ? !bit : bit);
  21. }
  22.  
  23. ld MonteCarlo(int rep)
  24. {
  25. int one = 0, zero = 0;
  26. while(rep--)
  27. {
  28. int dice = rollDice(0,9);
  29. int send = (dice < 3 ? 1 : 0);
  30. int rec = noise(send);
  31.  
  32. if(rec==11)
  33. {
  34. if(send)one++;
  35. else zero++;
  36. }
  37. }
  38.  
  39. cout<<"Kiek kartu pasirode 011: "<<(one+zero)<<"\n";
  40. cout<<"Kiek kartu is ju siuntem 1: "<<one<<"\n";
  41. return 1.0*one/(one+zero);
  42. }
  43.  
  44. int main()
  45. {
  46. ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  47. ld p0 = 0.7;
  48. ld fail = 0.3;
  49.  
  50. //P(1 | 011) = P(011 | 1) * P(1) / P(011)
  51. ld magicNumber = 1./8;
  52. ld magicNumber2 = p0*(fail*fail*(1-fail)) + (1-p0)*fail*(1-fail)*(1-fail);
  53. ld res1 = fail*(1-fail)*(1-fail)*(1-p0) / (magicNumber);
  54. ld res2 = fail*(1-fail)*(1-fail)*(1-p0) / (magicNumber2);
  55.  
  56. cout<<setprecision(3)<<fixed<<res1<<" "<<res2<<"\n";
  57. cout<<"Actual answer (with HP): "<<MonteCarlo(100000000)<<"\n";
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement