3 条题解
-
1
yejun LV 10 MOD @ 6 年前
-
04 年前@
/*
/
#define method_1
#ifdef method_1
/
先从n包花生中取出m(m>0)包,使得这m包花生的xor和为0(也就是把nim游戏的必败状态留给对方),
同时使得剩下的n-m包花生无论怎么取,xor和都不为0。
(实际上m就是花生的xor和为0的最长子序列)。
这么一来,对手就面临一个必败状态的nim游戏。
如果他从n-m根中取新的花生,
实际上就是新建一个xor和不为0的nim游戏,
这时轮到己方操作只要将这个新的nim游戏取到xor和为0即可。
(也就是让对方再次面临所有nim游戏均为必败状态的局面)。
寻找是否有Xor和=0的花生子序列,直接DFS无压力。
*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=14+5;
int n,a[maxn];
bool found;
int dfs(int x,int used,int now) {
if(x==n+1) {
if(!now&&used>0)found=1;
return 0;
}
dfs(x+1,used,now);
dfs(x+1,used+1,now^a[x]);
}
int main() {
ios::sync_with_stdio(false);
// freopen("丑奴儿.in","r",stdin);
found=0;
cin>>n;
for(int i=1; i<=n; i++) {
cin>>a[i];
}
dfs(1,0,0);
if(found) {
cout<<"TY";
} else {
cout<<"LPJ";
}return 0;
}
#endif
#ifdef method_2
/**/
#endif
#ifdef method_3
/**/
#endif
-
04 年前@
/*
/
#define method_1
#ifdef method_1
/
先从n包花生中取出m(m>0)包,使得这m包花生的xor和为0(也就是把nim游戏的必败状态留给对方),
同时使得剩下的n-m包花生无论怎么取,xor和都不为0。
(实际上m就是花生的xor和为0的最长子序列)。
这么一来,对手就面临一个必败状态的nim游戏。
如果他从n-m根中取新的花生,
实际上就是新建一个xor和不为0的nim游戏,
这时轮到己方操作只要将这个新的nim游戏取到xor和为0即可。
(也就是让对方再次面临所有nim游戏均为必败状态的局面)。
寻找是否有Xor和=0的花生子序列,直接DFS无压力。
*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=14+5;
int n,a[maxn];
bool found;
int dfs(int x,int used,int now) {
if(x==n+1) {
if(!now&&used>0)found=1;
return 0;
}
dfs(x+1,used,now);
dfs(x+1,used+1,now^a[x]);
}
int main() {
ios::sync_with_stdio(false);
// freopen("丑奴儿.in","r",stdin);
found=0;
cin>>n;
for(int i=1; i<=n; i++) {
cin>>a[i];
}
dfs(1,0,0);
if(found) {
cout<<"TY";
} else {
cout<<"LPJ";
}return 0;
}
#endif
#ifdef method_2
/**/
#endif
#ifdef method_3
/**/
#endif
- 1
信息
- 难度
- 4
- 分类
- (无)
- 标签
- (无)
- 递交数
- 30
- 已通过
- 17
- 通过率
- 57%
- 被复制
- 3
- 上传者