fork(1) download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <algorithm>
  5. #include <string>
  6. #include <set>
  7. #include <map>
  8. #include <vector>
  9. #include <ctime>
  10. #include <math.h>
  11. #include <memory.h>
  12.  
  13. using namespace std;
  14.  
  15. #define FOR(i, n) for (int i = 0; i < (int)n; ++i)
  16.  
  17. typedef long long LL;
  18. typedef vector<int> vi;
  19.  
  20.  
  21. int F(int n)
  22. {
  23. // n - number of matchsticks
  24. if (n <= 1)
  25. return n;
  26. set<int> values;
  27. for (int matchsticks = 1; matchsticks <= 2; ++matchsticks)
  28. {
  29. for (int i = 0; (i + matchsticks) <= n; ++i)
  30. {
  31. int grundyForTwoSubgamesCombined = F(i) ^ F(n - (i + matchsticks));
  32. values.insert(grundyForTwoSubgamesCombined);
  33. }
  34. }
  35. int res = 0;
  36. while (values.count(res) > 0)
  37. ++res;
  38. return res;
  39. }
  40.  
  41. int main()
  42. {
  43. // IIXIIIXXIIII
  44. cout << (F(2) ^ F(3) ^ F(4)) << endl;
  45. // III
  46. cout << F(3) << endl;
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
0
3