SG 函数 hdu1524 & poj 2425 hdu1524 A Chess Game
2016-08-02 22:58
405 查看
本来只是简单的一道水体,但是没过4级的我,完全看不懂题目,写到中间还有出错误坑我wr了好久,逼我写个解题报告
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int game[1050][1050];
int sg[1050];
int n; /// 标号0~n-1
int flag[1050];
int dfs(int d)
{
if(sg[d]!=-1) return sg[d];
bool flag[1010]={0};
memset(flag,0,sizeof(flag));
for(int i=0;i<n;i++)
if(game[d][i]==1)
flag[dfs(i)]=1;
for(int i=0;;i++) if(flag[i]==0)
return sg[d]=i;
}
int main(){
while(scanf("%d",&n) != EOF){
memset(game,-1,sizeof(game));
memset(sg,-1,sizeof(sg));
int xi,x;
for (int i = 0;i < n;++i){
scanf("%d",&xi);
if (xi == 0) sg[i] = 0;
for (int j = 0;j < xi;++j){
scanf("%d",&x);
game[i][x] = 1;
}
}
int m;
while(scanf("%d",&m) && m){
int idx,ans = 0;
for (int i = 0;i < m;++i){
scanf("%d",&idx);
ans ^= dfs(idx);
}
printf(ans ? "WIN\n":"LOSE\n");
}
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int game[1050][1050];
int sg[1050];
int n; /// 标号0~n-1
int flag[1050];
int dfs(int d)
{
if(sg[d]!=-1) return sg[d];
bool flag[1010]={0};
memset(flag,0,sizeof(flag));
for(int i=0;i<n;i++)
if(game[d][i]==1)
flag[dfs(i)]=1;
for(int i=0;;i++) if(flag[i]==0)
return sg[d]=i;
}
int main(){
while(scanf("%d",&n) != EOF){
memset(game,-1,sizeof(game));
memset(sg,-1,sizeof(sg));
int xi,x;
for (int i = 0;i < n;++i){
scanf("%d",&xi);
if (xi == 0) sg[i] = 0;
for (int j = 0;j < xi;++j){
scanf("%d",&x);
game[i][x] = 1;
}
}
int m;
while(scanf("%d",&m) && m){
int idx,ans = 0;
for (int i = 0;i < m;++i){
scanf("%d",&idx);
ans ^= dfs(idx);
}
printf(ans ? "WIN\n":"LOSE\n");
}
}
return 0;
}
相关文章推荐
- POJ 2425 && HDU 1524 A Chess Game(博弈论)
- POJ2425 && HDU1524_ A Chess Game_树形博弈
- HDU-1524-A Chess Game && POJ-2425 【sg】
- hdu 1524 A Chess Game (SG)
- POJ 2425 A Chess Game#树形SG
- HDU 1524 - A Chess Game(SG)
- POJ 2425 A Chess Game (博弈)
- (step 8.2.13)hdu 1524(A Chess Game)
- POJ2425 A Chess Game(博弈)
- hdu 1524 A Chess Game
- [poj 2425]A Chess Game
- pku 2425 A Chess Game (SG)
- POJ 2425 A Chess Game(SG函数的有向图博弈游戏)
- hdu1524 A Chess Game
- HDU_1524 A Chess Game (sg函数)
- poj 1082 Calendar Game & HDU 1079 Calendar Game
- (step 8.2.13)hdu 1524(A Chess Game)
- poj 2425 A Chess Game_sg函数
- A Chess Game(poj 2425)
- poj 2425 A Chess Game (sg函数)