A Chess Game

http://poj.org/problem?id=2425

// File Name: poj2425.cpp
// Author: bo_jwolf
// Created Time: 2013年10月06日 星期日 16:06:50

#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>

using namespace std;
const int maxn = 1005;
int n, m, temp, sg[ maxn ];
vector<vector<int> >Q;

int getSg( int n ){
	if( sg[ n ] != -1 )
		return sg[ n ];
	int vis[ maxn ] = { 0 };
	for( int i = 0; i < Q[ n ].size(); ++i ){
		if( sg[ Q[ n ][ i ] ] == -1 ){
			sg[ Q[ n ][ i ] ] = getSg( Q[ n ][ i ] );
		}
		vis[ sg[ Q[ n ][ i ] ] ] = 1;
	}
	for( int i = 0; ; ++i ){
		if( !vis[ i ] )
			return i;
	}
	return 0;
}

int main(){
	while( scanf( "%d", &n ) != EOF ){
		Q.clear();
		Q.resize( n + 1 );
		memset( sg, -1, sizeof( sg ) );
		for( int i = 0; i < n; ++i ){
			scanf( "%d", &m );
			while( m-- ){
				scanf( "%d", &temp );
				Q[ i ].push_back( temp );
			}
		}
		while( scanf( "%d", &m ) != EOF && m ){
			int ans = 0;
			while( m-- ){
				scanf( "%d", &temp );
				ans ^= getSg( temp );
			}
			if( ans )
				printf( "WIN\n" );
			else
				printf( "LOSE\n" );
		}
	}
return 0;
}


你可能感兴趣的:(A Chess Game)