【bytoj】博弈论

进了410以后用了两天的时间肝完了博弈论的例题

本人菜的要死

所以博弈论还是留给瓶子怪等人讲解吧

在这里就仅仅放上代码

eg1

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int a[500005];
 4 int main() {
 5     int n;
 6     cin >> n;
 7     int check = 0;
 8     for (int i = 1; i <= n; i++) {
 9         cin >> a[i];
10         check ^= a[i];
11     }
12     if (!check) {
13         cout << "lose" << endl;
14         return 0;
15     }
16     for (int i = 1; i <= n; i++) {
17         if ((check ^ a[i]) < a[i]) {
18             cout << a[i] - (check ^ a[i]) << " " << i << endl;
19             for (int j = 1; j <= n; j++) {
20                 if (j != i) {
21                     cout << a[j] << " ";
22                 } else {
23                     cout << (check ^ a[i]) << " ";
24                 }
25             }
26             break;
27         }
28     }
29     return 0;
30 }

eg2

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 inline void work(int n) {
 4     if (n == 1) {
 5         cout << "FastestFinger" << endl;
 6         return;
 7     }
 8     if (n == 2) {
 9         cout << "Ashishgup" << endl;
10         return;
11     }
12     bool flag = false;
13     if (n % 2 == 0) {
14         for (int i = 0; i <= 29; i++) {
15             if ((1 << i) == n) {
16                 flag = true;
17                 break;
18             }
19         }
20         if (!flag) {
21             flag = true;
22             for (int i = 3; i * i <= n; i++) {
23                 if (n % i == 0) {
24                     flag = false;
25                     break;
26                 }
27             }
28         }
29     }
30     if (!flag) {
31         cout << "Ashishgup" << endl;
32     } else {
33         cout << "FastestFinger" << endl;
34     }
35 }
36 int main() {
37     int n, t;
38     cin >> t;
39     while (t--) {
40         cin >> n;
41         work(n);
42     }
43     return 0;
44 }

eg3

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 12414;
 4 int sg[maxn], a[maxn];
 5 inline int SG(int n) {
 6     if (sg[n] != -1) {
 7         return sg[n];
 8     }
 9     bool flag[maxn];
10     memset(flag, 0, sizeof(flag));
11     int p = 0;
12     for (int i = 1; i * i <= n; i++) {
13         if (n % i) {
14             continue;
15         }
16         if (i < n) {
17             p ^= SG(i);
18         }
19         if (n / i > 1 and n / i < n and i * i != n) {
20             p ^= SG(n / i);
21         }
22     }
23     for (int i = 1; i * i <= n; i++) {
24         if (n % i) {
25             continue;
26         }
27         if (i < n) {
28             flag[p ^ sg[i]] = 1;
29         }
30         if (n / i > 1 and n / i < n and i * i != n) {
31             flag[p ^ sg[(n / i)]] = 1;
32         }
33     }
34     int ans = 0;
35     while (flag[ans]) {
36         ans++;
37     }
38     sg[n] = ans;
39     return ans;
40 }
41 inline int work(int n) {
42     memset(sg, -1, sizeof(sg));
43     sg[1] = 0;
44     int ans = 0;
45     for (int i = 1; i <= n; i++) {
46         cin >> a[i];
47         ans ^= SG(a[i]);
48     }
49     return ans;
50 }
51 int main() {
52     int n;
53     while (cin >> n) {
54         if (work(n)) {
55             cout << "freda" << endl;
56         } else {
57             cout << "rainbow" << endl;
58         }
59     }
60     return 0;
61 }

eg4

警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!警钟珏烂!

某谷上有一摸一样的一道题,但是数据范围和bytoj完全不一致

如果修改了maxn以后一定要用clang!

要不然不得分(各种意义上的,包括生物卷)

 1 #include <bits/stdc++.h>
 2 #define int long long
 3 
 4 using namespace std;
 5 const int maxn = 1000;
 6 int sg[maxn][maxn];
 7 inline int SG(int n, int m) {
 8     if (sg[n][m] != -1) {
 9         return sg[n][m];
10     }
11     int f[205] = {};
12     for (int i = 2; i <= n - 2; i++) {
13         f[SG(i, m) ^ SG(n - i, m)] = 1;
14     }
15     for (int i = 2; i <= m - 2; i++) {
16         f[SG(n, i) ^ SG(n, m - i)] = 1;
17     }
18     for (int i = 0; i <= 200; i++) {
19         if (!f[i]) {
20             return sg[n][m] = i;
21         }
22     }
23 }
24 signed main() {
25     memset(sg, -1, sizeof(sg));
26     int n, m;
27     while (cin >> n >> m) {
28         if (SG(n, m)) {
29             cout << "WIN" << endl;
30         } else {
31             cout << "LOSE" << endl;
32         }
33     }
34     return 0;
35 }

 

posted @ 2024-06-19 16:22  类人群星闪耀时  阅读(4)  评论(0编辑  收藏  举报