HDU 1524

有向无环图上求SG值,比较正统的问题,解决思路也很正常,只是可惜我的深搜水平实在太差了

//HDU-1524.cpp
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
//const double pai = acos(-1.0);
const double pai = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
typedef long long love_live;
int sg[1117], arr[1117][1117], vex[1117];

void init(){
	memset(vex, 0, sizeof(vex));
	memset(sg, -1, sizeof(sg));
	memset(arr, 0, sizeof(arr));
	return ;
}

int getsg(int x){
	if(sg[x] != -1){
		return sg[x];
	}
	int i, j, k;
	bool mex[1117] = {0};
	for(i = 0; i < vex[x]; ++i){
		mex[getsg(arr[x][i])] = 1;
	}
	for(i = 0; ; ++i){
		if(!mex[i]){
			return sg[x] = i;
		}
	}
}

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
//	freopen("output", "w", stdout);
	freopen("input", "r", stdin);
#endif
	int n, m, i, j, k, x;
	while(scanf("%d", &n) != EOF){
		if(n == 0){
			break;
		}
		init();
		for(i = 0; i < n; ++i){
			scanf("%d", &vex[i]);
			if(vex[i] == 0){
				sg[i] = 0;
			}
			for(j = 0; j < vex[i]; j++){
				scanf("%d", &arr[i][j]);
			}
		}
		// for(i = 0; i < n; ++i){
		// 	cout << vex[i] << " ";
		// }
		// cout << endl;
		// for(i = 0; i < n; ++i){
		// 	for(j = 0; j < vex[i]; ++j){
		// 		cout << arr[i][j] << " ";
		// 	}
		// 	cout << endl;
		// }
		while(1){
			scanf("%d", &m);
			if(m == 0){
				break;
			}
			else{
				int ans = 0;
				for(i = 0; i < m; ++i){
					scanf("%d", &k);
					ans ^= getsg(k);
				}
				if(ans != 0){
					printf("WIN\n");
				}
				else{
					printf("LOSE\n");
				}
			}
		}
	}
return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值