CF63E Sweets Game
打表发现只有 \(103\) 种行动方法。
打表代码:
简单来说就是只处理行移动过,然后转两次再做。
#include<bits/stdc++.h>
#include<atcoder/all>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define pii pair<int, int>
#define F(i,l,r) for(int i(l); i <= (r); ++ i)
#define G(i,r,l) for(int i(r); i >= (l); -- i)
//#define int ll
using namespace std;
using namespace atcoder;
using ll = long long;
const int N = 1e6;
int a[100];
int get1(int x){
return (1 << a[x]);
}
int get2(int x, int y){
return (1 << a[x]) + (1 << a[y]);
}
int get3(int x, int y, int z){
return (1 << a[x]) + (1 << a[y]) + (1 << a[z]);
}
int get4(int x, int y, int z, int p){
return (1 << a[x]) + (1 << a[y]) + (1 << a[z]) + (1 << a[p]);
}
int get5(int x, int y, int z, int p, int q){
return (1 << a[x]) + (1 << a[y]) + (1 << a[z]) + (1 << a[p]) + (1 << a[q]);
}
vector<int> v;
void task(){
F(i, 0, 1){
v.pb(get2(i, i + 1));
}
F(i, 3, 5){
v.pb(get2(i, i + 1));
}
F(i, 7, 10){
v.pb(get2(i, i + 1));
}
F(i, 12, 14){
v.pb(get2(i, i + 1));
}
F(i, 16, 17){
v.pb(get2(i, i + 1));
}
v.pb(get3(0, 1, 2));
F(i, 3, 4){
v.pb(get3(i, i + 1, i + 2));
}
F(i, 7, 9){
v.pb(get3(i, i + 1, i + 2));
}
F(i, 12, 13){
v.pb(get3(i, i + 1, i + 2));
}
v.pb(get3(16, 17, 18));
v.pb(get4(3, 4, 5, 6));
v.pb(get4(7, 8, 9, 10));
v.pb(get4(8, 9, 10, 11));
v.pb(get4(12, 13, 14, 15));
v.pb(get5(7, 8, 9, 10, 11));
}
void Main(){
F(i, 0, 18){
a[i] = i;
v.pb(get1(i));
}
task();
a[0] = 7;
a[1] = 3;
a[2] = 0;
a[3] = 12;
a[4] = 8;
a[5] = 4;
a[6] = 1;
a[7] = 16;
a[8] = 13;
a[9] = 9;
a[10] = 5;
a[11] = 2;
a[12] = 17;
a[13] = 14;
a[14] = 10;
a[15] = 6;
a[16] = 18;
a[17] = 15;
a[18] = 11;
task();
a[0] = 2;
a[1] = 6;
a[2] = 11;
a[3] = 1;
a[4] = 5;
a[5] = 10;
a[6] = 15;
a[7] = 0;
a[8] = 4;
a[9] = 9;
a[10] = 14;
a[11] = 18;
a[12] = 3;
a[13] = 8;
a[14] = 13;
a[15] = 17;
a[16] = 7;
a[17] = 12;
a[18] = 16;
task();
int sz = v.size();
printf("size = %d\n", sz);
for(auto x : v){
printf("%d, ", x);
}
return ;
}
signed main(){
// freopen("fg.in", "r", stdin);
freopen("fg.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T;
T = 1;
while(T --) Main();
return fflush(0), 0;
}
所以我们考虑爆搜,把这个 \(19\) 格棋盘压成一个二进制数,然后枚举每一种行动,用记忆化搜索保证效率。
判定方式:(这也是博弈论的一个套路)
如果无论先手怎么出招,后手都赢,则先手必输。
如果先手存在一种出招,后手必败,则先手必胜。
于是直接深搜就做完了。
#include<bits/stdc++.h>
//#include<atcoder/all>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define pii pair<int, int>
#define F(i,l,r) for(int i(l); i <= (r); ++ i)
#define G(i,r,l) for(int i(r); i >= (l); -- i)
//#define int ll
using namespace std;
//using namespace atcoder;
using ll = long long;
const int N = 1e6;
char s[100][5];
int a[100], x = 0;
int f[N];
int mov[110] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 3, 6, 24, 48, 96, 384, 768, 1536, 3072, 12288, 24576, 49152, 196608, 393216, 7, 56, 112, 896, 1792, 3584, 28672, 57344, 458752, 120, 1920, 3840, 61440, 3968, 136, 9, 4352, 272, 18, 73728, 8704, 544, 36, 147456, 17408, 1088, 294912, 34816, 137, 4368, 274, 74240, 8736, 548, 148480, 17472, 296960, 4370, 74272, 8740, 148544, 74276, 68, 2112, 34, 1056, 33792, 17, 528, 16896, 278528, 264, 8448, 139264, 4224, 69632, 2116, 1058, 33824, 529, 16912, 279040, 8456, 139520, 69760, 33826, 16913, 279056, 139528, 279057};
int dfs(int x){
if(f[x] != -1) return f[x];
if(x == 0){
f[x] = 0;
return f[x];
}
if(__builtin_popcount(x) == 1){
f[x] = 1;
return f[x];
}
int op = 1;
F(i, 0, 102){
int B = mov[i];
if((B & x) != B) continue;
if(dfs(x - B) == 0){
op = 0;
break;
}
}
f[x] = (op ^ 1);
return f[x];
}
void Main(){
F(i, 0, 525000){
f[i] = -1;
}
F(i, 1, 19){
cin >> s[i];
x = (x * 2) + (s[i][0] == 'O');
}
dfs(x);
if(f[x] == 1) cout << "Karlsson";
else cout << "Lillebror";
return ;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T;
T = 1;
while(T --) Main();
return fflush(0), 0;
}

浙公网安备 33010602011771号