fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <tuple>
  5. #include <random>
  6. #include <algorithm>
  7.  
  8. //AB_Vote_System?
  9.  
  10. typedef std::vector<std::uintmax_t> DType;
  11.  
  12. std::tuple<std::uintmax_t, std::uintmax_t> DoMajorityVote(std::uintmax_t V,unsigned int S=0) {//TaSuUKeThu
  13. std::uintmax_t B = 0;
  14. std::uintmax_t R = 0;
  15.  
  16. std::minstd_rand mr(S);
  17.  
  18.  
  19. for (std::uintmax_t i = 0; i < V; i++) {
  20. if (mr()%2) {
  21. B++;
  22. }
  23. else {
  24. R++;
  25. }
  26. }
  27.  
  28. return{ B,R };
  29. }
  30.  
  31. DType MakeVector(std::uintmax_t BL, std::uintmax_t RL, unsigned int S = 0, bool IsShuffle = true) {
  32.  
  33. DType R;
  34.  
  35. for (std::uintmax_t i = 0; i < BL; i++) {
  36. R.push_back(1);
  37. }
  38. for (std::uintmax_t i = 0; i < RL; i++) {
  39. R.push_back(2);
  40. }
  41.  
  42. if (IsShuffle) {
  43. std::mt19937 mt(S);
  44. std::shuffle(R.begin(), R.end(), mt);
  45. }
  46.  
  47. return R;
  48. }
  49.  
  50. std::tuple<std::uintmax_t, std::uintmax_t, std::uintmax_t> Lottery(DType D, unsigned int S = 0) {
  51.  
  52. if (D.size() <= 2) {
  53. return { 0,1,1 };
  54. }
  55.  
  56. DType R;
  57.  
  58. std::minstd_rand mr(S);
  59.  
  60. for (std::uintmax_t i = 0; i < 3; i++) {
  61. std::uniform_int_distribution<> ui(0, D.size()-1);
  62. std::uintmax_t V = ui(mr);
  63. R.push_back(D[V]);
  64. D.erase(D.begin() + V);
  65. }
  66.  
  67. return { R[0],R[1],R[2] };
  68.  
  69. }
  70.  
  71. std::uintmax_t Janken(unsigned int BS = 0, unsigned int RS = 10) {
  72.  
  73. std::mt19937 BR(BS);
  74. std::mt19937 RR(RS);
  75.  
  76. std::uniform_int_distribution<> ui(0, 100);
  77.  
  78. std::uintmax_t BD = ui(BR);
  79. std::uintmax_t RD = ui(RR);
  80.  
  81. BR.discard(RD);
  82. RR.discard(BD);
  83.  
  84. std::uintmax_t BH = 0;
  85. std::uintmax_t RH = 0;
  86. do {
  87.  
  88. BH = ui(BR);
  89. RH = ui(RR);
  90. } while (BH==RH);
  91.  
  92. return BH > RH ? 1 : 0;
  93. }
  94.  
  95. std::tuple<std::uintmax_t,std::uintmax_t,std::uintmax_t> DoHoge() {
  96. std::uintmax_t BV = 0;
  97. std::uintmax_t RV = 0;
  98.  
  99. std::uintmax_t L = 1000000;
  100. std::uintmax_t Scale = 100;
  101.  
  102. std::random_device rd;
  103. unsigned int BS = 0;
  104. unsigned int RS = 0;
  105. unsigned int SS = rd();
  106.  
  107. do {
  108. BS = rd();
  109. RS = rd();
  110. } while (BS == RS);
  111.  
  112. std::tie(BV, RV) = DoMajorityVote(L,SS);
  113.  
  114. DType D = MakeVector((BV / (double)L) * Scale + 0.4, (RV / (double)L) * Scale + 0.4,SS);
  115.  
  116. std::uintmax_t One=0;
  117. std::uintmax_t Tow=0;
  118. std::uintmax_t Three=0;
  119. std::tie(One, Tow, Three) = Lottery(D,SS);
  120.  
  121. std::uintmax_t J = -1;
  122.  
  123. if (One != Tow ) {
  124. J=Janken(BS,RS);
  125. }
  126. else if (One != Three) {
  127. J=Janken(BS,RS);
  128. }
  129. else if (Tow != Three) {
  130. J=Janken(BS,RS);
  131. }
  132. else {
  133. J = One;
  134. }
  135.  
  136. return {J,BV,RV};
  137. }
  138.  
  139. int main() {
  140.  
  141. std::size_t L = 7;
  142.  
  143. for (std::size_t i = 0; i < L; i++) {
  144. std::uintmax_t A, B, R;
  145.  
  146. std::tie(A, B, R) = DoHoge();
  147.  
  148. std::cout << "Winner Is " << (A == 1 ? "First" : "Second") << "!" << std::endl;
  149. std::cout << B << " Vs. " << R << std::endl;
  150. std::cout << std::endl;
  151. }
  152.  
  153. return 0;
  154. }
  155.  
Success #stdin #stdout 0.04s 4480KB
stdin
Standard input is empty
stdout
Winner Is First!
499845 Vs. 500155

Winner Is First!
500061 Vs. 499939

Winner Is Second!
499395 Vs. 500605

Winner Is First!
500647 Vs. 499353

Winner Is Second!
500338 Vs. 499662

Winner Is Second!
500769 Vs. 499231

Winner Is First!
500402 Vs. 499598