Question: give you n strings, give you a sequence, two people take one character in turn so that the existing string is the prefix in N strings, and whoever can't take it will lose this game, but if they want to play K games, whoever wins in K games is equal to winning the entire game.
Solution: find out whether the dictionary tree has a strategy to lose or win. If there is a strategy to win or lose at the same time, it must be a first win. If only yes, we only need to discuss K parity, if you only need to lose, it must be second.
Solution code:
1 // file name: 1.cpp 2 // Author: darkdream 3 // created time: saturday, July 12, 2014, 16 seconds, 4 5 # include <vector> 6 # include <list> 7 # include <map> 8 # include <set> 9 # include <deque> 10 # include <stack> 11 # include <bitset> 12 # include <algorithm> 13 # include <functional> 14 # include <numeric> 15 # include <utility> 16 # include <sstream> 17 # include <iostream> 18 # include <iomanip> 19 # include <cstdio> 20 # include <Cmath> 21 # include <cstdlib> 22 # include <cstring> 23 # include <ctime> 24 # include <climits> 25 # include <queue> 26 27 using namespace STD; 28 29 struct node {30 int num; 31 int OK; 32 int ok1; 33 struct node * Next [30]; 34}; 35 struct node * newnode () {36 struct node * P = (node *) malloc (sizeof (node); 37 for (INT I = 0; I <30; I ++) 38 P-> next [I] = NULL; 39 p-> OK = 0; 40 p-> num = 0; 41 return P; 42} 43 char STR [100004]; 44 int Len; 45 void build (struct node * P, int I) 46 {47 48 int K = STR [I]-'A '; 49 if (I = Len) 50 return; 51 if (p-> next [k] = NULL) 52 {53 struct node * t = newnode (); 54 T-> num ++; 55 p-> next [k] = T; 56 build (p-> next [K], I + 1 ); 57} 58 else {59 p-> next [k]-> num + = 1; 60 build (p-> next [K], I + 1 ); 61} 62 int Tok = 0; 63 int NOK = 0; 64 int t1ok = 0; 65 for (INT I = 0; I <30; I ++) 66 {67 If (p-> next [I]! = NULL) 68 {69 NOK = 1; 70 If (p-> next [I]-> OK = 0) 71 Tok = 1; 72 If (p-> next [I]-> ok1 = 1) 73 t1ok = 1; 74} 75} 76 if (! NOK | Tok) 77 p-> OK = 1; 78 else p-> OK = 0; 79 if (NOK) 80 {81 If (t1ok) 82 p-> ok1 = 0; 83 else p-> ok1 = 1; 84} else {85 p-> ok1 = 0; 86} 87} 88 int ans; 89 void find (struct node * P, int I) 90 {91 int K = STR [I]-'A'; 92 if (I = Len) 93 {94 ans = p-> num; 95 return; 96} 97 If (p-> next [k] = NULL) 98 {99 return; 100} else find (p-> next [K], I + 1); 101} 102 int main () {103 int N, K; 104 105 struct Node * head = newnode (); 106 scanf ("% d", & N, & K); 107 while (n --) {108 scanf ("% s ", str); 109 Len = strlen (STR); 110 build (Head, 0); 111} 112 // printf ("% d \ n", head-> OK, head-> ok1); 113 If (Head-> OK) 114 {115 If (! Head-> ok1) 116 printf ("first \ n"); 117 else {118 If (K % 2 = 1) 119 printf ("first \ n "); 120 else printf ("second \ n"); 121} 122} else {123 printf ("second \ n"); 124} 125 return 0; 126}View code