博弈论nim^|sg函数
acwing过过一遍,不用就会淡忘,好消息是再看一眼就能想起来了😇
lc1908
nim游戏:把所有堆的数量异或,结果非零则当前玩家能赢
非零先手玩家只用将其变为0,然后镜像后手玩家操作,后手必败
class Solution {
public:
bool nimGame(vector<int>& piles) {
int t = 0;
for(int p : piles){
t ^= p;
}
return t != 0;
}
};
acwing过过一遍,不用就会淡忘,好消息是再看一眼就能想起来了😇
lc1908
nim游戏:把所有堆的数量异或,结果非零则当前玩家能赢
非零先手玩家只用将其变为0,然后镜像后手玩家操作,后手必败
class Solution {
public:
bool nimGame(vector<int>& piles) {
int t = 0;
for(int p : piles){
t ^= p;
}
return t != 0;
}
};