fork(3) download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define fr(a,b) for(int i = a; i < b; i++)
  4. #define mod 1000000007
  5. #define triplet pair<int,pair<int,int>>
  6. #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
  7. using namespace std;
  8.  
  9. ll my_coins = 10000;
  10. bool myPrevDecision;
  11. ll myPrevBet = 0;
  12.  
  13. void fresh_run_user_init()
  14. {
  15. my_coins = 10000;
  16. myPrevBet = 0;
  17. }
  18.  
  19. // baseline implementation, scores ~ 10k.
  20. pair<ll,bool> make_bet(bool previousSpinResult)
  21. {
  22. my_coins = (my_coins + ((previousSpinResult == myPrevDecision)?myPrevBet:-myPrevBet));
  23. myPrevDecision = rand()%2;
  24.  
  25. if(my_coins >= 100)
  26. {
  27. myPrevBet = 100;
  28. return {100, myPrevDecision};
  29. }
  30. else
  31. {
  32. myPrevBet = 0;
  33. return {0,myPrevDecision};
  34. }
  35. }
  36.  
  37. //tester's code
  38. int spinRoulette()
  39. {
  40. return rand()%2;
  41. }
  42.  
  43. int main(){
  44. srand(time(0));
  45.  
  46. int RUNS = 10000;
  47. ll avg_score = 0;
  48. //Can u design a strategy such that avg_score/score overflows?
  49. for(int ith_run = 0; ith_run < RUNS; ith_run++)
  50. {
  51. fresh_run_user_init();
  52.  
  53. ll user_coins = 10000;
  54. int spins_left = 5000;
  55.  
  56. // spin result, 0 means even and 1 means odd.
  57. bool result = spinRoulette();
  58.  
  59. while(spins_left--)
  60. {
  61. pair<ll,bool> user_bet = make_bet(result);
  62. //You cannot make a bet larger than the money you have.
  63.  
  64. assert(user_bet.first <= user_coins);
  65. //spin the roulette.
  66. result = spinRoulette();
  67.  
  68. //lost/won
  69. if(result == user_bet.second)
  70. user_coins += user_bet.first;
  71. else user_coins -= user_bet.first;
  72. }
  73.  
  74. avg_score += user_coins;
  75. }
  76.  
  77. cout << "YOUR BOT SCORED : "<<(1.0*avg_score)/RUNS;
  78. return 0;
  79. }
  80. //End
  81.  
Success #stdin #stdout 1.29s 4496KB
stdin
Standard input is empty
stdout
YOUR BOT SCORED : 9996.1