luoguP3185 [HNOI2007]分裂游戏 枚举 + 博弈论
生活随笔
收集整理的這篇文章主要介紹了
luoguP3185 [HNOI2007]分裂游戏 枚举 + 博弈论
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
每個位置的瓶子中的每個石子是一個獨立的游戲
只要計算出他們的\(sg\)值即可
至于方案數,反正不多\(n^3\)暴力枚舉即可
反正怎么暴力都能過啊
復雜度\(O(Tn^3)\)
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std;#define ll long long #define ri register int #define rep(io, st, ed) for(ri io = st; io <= ed; io ++) #define drep(io, ed, st) for(ri io = ed; io >= st; io --)#define gc getchar inline int read() {int p = 0, w = 1; char c = gc();while(c < '0' || c > '9') { if(c == '-') w = -1; c = gc(); }while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();return p * w; }int n, sg[25], mex[105];inline void get_sg() {sg[n] = 0;drep(i, n - 1, 1) {memset(mex, 0, sizeof(mex));rep(j, i + 1, n) rep(k, j, n)mex[sg[j] ^ sg[k]] = 1;rep(j, 0, 100)if(!mex[j]) { sg[i] = j; break; }} }int main() {int T = read();while(T --) {n = read(); get_sg();int SG = 0;rep(i, 1, n) SG ^= (read() & 1) * sg[i];if(!SG) {printf("-1 -1 -1\n");printf("0\n"); continue;}int ans = 0, flag = 0;rep(i, 1, n) rep(j, i + 1, n) rep(k, j, n)if((SG ^ sg[i] ^ sg[j] ^ sg[k]) == 0) {if(!flag) { printf("%d %d %d\n", i - 1, j - 1, k - 1); flag = 1; }ans ++;}printf("%d\n", ans);}return 0; }
轉載于:https://www.cnblogs.com/reverymoon/p/10152046.html
總結
以上是生活随笔為你收集整理的luoguP3185 [HNOI2007]分裂游戏 枚举 + 博弈论的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CodeForces - 500A-Ne
- 下一篇: mui的学习图片预览