fork download
  1. #include <vector>
  2. #include <iostream>
  3. #include <random>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. mt19937 g(random_device{}());
  11. vector<int> v;
  12. for(int i = 0; i < 28; ++i)
  13. if (i < 7) v.push_back(1);
  14. else v.push_back(0);
  15. int total = 0, ok = 0;
  16. for(int i = 0; i < 1000000; ++i)
  17. {
  18. shuffle(v.begin(),v.end(),g);
  19. if (v[0]+v[1]+v[2]+v[3] == 1) ++ok;
  20. ++total;
  21. }
  22. cout << double(ok)/total << endl;
  23. }
  24.  
  25.  
  26.  
Success #stdin #stdout 0.47s 4380KB
stdin
Standard input is empty
stdout
0.45423