Time Limit:20 Sec
Memory limit:256 MB
Topic Connection
Http://codeforces.com/gym/100500/attachments
Description
Let's check another challenge of the IBM ICPC Chill Zone, a poetry challenge. One says a poetry string that starts with an 中文版 and ends with a 中文版, the second should say a poetr Y string that starts with the same letter, the previous string ended with.
Given The poetry string sets representing the known strings for each player. Each player can use each of his strings only once. If during the player turn he can not say any string, he loses. Assuming both players play optimally well determine which player wins the game depending on the given both sets.
Input
The first line contains an integer T represent the number of the following test cases. Each test case starts with a integer n the number of strings in the first player set. Each of the next n lines contains a string of the first player set. Then read an integer m, which'll be succeeded by M lines describing the strings of the second player. No string in the input would start or finish with a white space, only lowercase letters. The length of each string in the input would not exceed letters. 1≤n≤9 1≤m≤9 1≤t≤10
Output
For each test case, print one line saying which player should win if they is so clever to play it perfectly and assuming That all one knows the set of the other player. Discarding quotes, print "Game_i:_player1" to denote the wining of the first player or "game_i:_player2" to denote the win O F the second player where ' I ' represents the game number starting from 1. Replace the underscores with spaces.
Sample Input
2 3 A poetry string a poetry string starting with a a poetry string ending with a 3 generated word a word ending with B po Etry 2 either one or both random string 3 Another test case one greatest poetry be the winner
Sample Output
Game 1:player2 Game 2:player1
HINT
Test instructions
Word solitaire, who can't pick up, even if who loses
are very smart cases
Exercises
After the conversion into graph theory, the direct DFS explosion search is good!
Code
#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=202501;#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//*************************************************************************************Chars1[ -][20000];Chars2[ -][20000];vector<int> e[ -];intvis[ -];intDfsintx) { for(intI=0; I<e[x].size (); i++) { if(Vis[e[x][i]])Continue; Vis[e[x][i]]=1; if(!DFS (E[x][i])) {Vis[e[x][i]]=0; return 1; } } return 0;}intMain () {intt=read (); for(intcas=1; cas<=t;cas++) {memset (Vis,0,sizeof(VIS)); for(intI=0;i< -; i++) e[i].clear (); intn=read (); for(intI=0; i<n;i++) gets (S1[i]); intm=read (); for(intI=0; i<m;i++) gets (S2[i]); for(intI=0; i<n;i++) { intlen=strlen (S1[i]); for(intj=0; j<m;j++) { if(s1[i][len-1]==s2[j][0]) E[i].push_back (J+9); } } for(intI=0; i<m;i++) { intlen=strlen (S2[i]); for(intj=0; j<n;j++) { if(s2[i][len-1]==s1[j][0]) E[i+9].push_back (i); } } intflag=0; for(intI=0; i<n;i++) {Vis[i]=1; if(!DFS (i)) {Flag=1; Break; } Vis[i]=0; } if(flag) printf ("Game%d:player1\n", CAs); Elseprintf ("Game%d:player2\n", CAs); }}
Codeforces Gym 100500A A. Poetry Challenge DFS