"CF" 556D A lot of games

Source: Internet
Author: User

Build Trie tree, you can get 4 kinds of nodes: win point, must negative point, completely dominate the point (can win can be negative), completely unable to dominate the point (unable to control the final outcome). Recursive to the leaf node, that is, to win the point, a retrospective discussion of the situation. Note that leaf nodes use attribute n to control, and N indicates the number of node nodes in the current node, and the leaf node has no son.

1 /*456D*/2#include <iostream>3#include <string>4#include <map>5#include <queue>6#include <Set>7#include <stack>8#include <vector>9#include <deque>Ten#include <algorithm> One#include <cstdio> A#include <cmath> -#include <ctime> -#include <cstring> the#include <climits> -#include <cctype> -#include <cassert> - using namespacestd; +  -typedefstructtrie_t { +     intN; A     intnext[ -]; at trie_t () { -n =0; -Memset (Next,0,sizeof(next)); -     } - } trie_t; -  in Const intMAXN = 1e5+5; -  to trie_t T[MAXN]; + intL =0; - CharS[MAXN]; the intN, M; *  $ intNewtrie () {Panax Notoginseng     return++L; - } the  + voidCreateChar*s,intRT) { A     intp =RT; the     inti =0, id; +  -      while(S[i]) { $id = s[i]-'a'; $         if(T[p].next[id] = =0) { -T[p].next[id] = + +L; -++T[P].N; the         } -p =T[p].next[id];Wuyi++i; the     } - } Wu  - intDfsintRT) { About     inti; $     intSt =0; -      -     if(T[RT].N = =0) -         return 2; A  +      for(i=0; i< -; ++i) { the         if(T[rt].next[i]) -St |=DFS (T[rt].next[i]); $     } the     Switch(ST) { the      Case 0: the         return 3; the      Case 1: -         return 2; in      Case 2: the         return 1; the      Case 3: About         return 0; the     default: the         return 0; the     } + } -  the Bayi intMain () { the     intI, J, K; the  - #ifndef Online_judge -Freopen ("data.in","R", stdin); theFreopen ("Data.out","W", stdout); the     #endif the  thescanf"%d%d", &n, &m); -     //build Trie the      for(i=0; i<n; ++i) { thescanf"%s", s); theCreate (S,0);94     } the     //get the key point the     intSt =0; the      for(i=0; i< -; ++i) {98         if(t[0].next[i]) AboutSt |= DFS (t[0].next[i]); -     }101     102     if(St = =3) {103Puts" First");104         return 0; the}Else if(St = =0) {106Puts"Second");107         return 0;108     }109     if(St = =1) { thePuts"Second");111         return 0; the     }113     if(M &1) { thePuts" First"); the}Else { thePuts"Second");117     }118 119 #ifndef Online_judge -printf"Time =%d.\n", (int) clock ());121     #endif122 123     return 0;124}

"CF" 556D A lot of games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.