构建trie树,可以得到4类结点:必胜点,必负点,完全主宰点(可胜可负),完全无法主宰点(无法控制最终胜负)。递归到叶子结点,即为必胜点,回溯分情况讨论。注意叶子结点使用属性n来控制,n表示当前结点的儿子结点的数目,叶子结点没有儿子。

  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>
 10 #include <algorithm>
 11 #include <cstdio>
 12 #include <cmath>
 13 #include <ctime>
 14 #include <cstring>
 15 #include <climits>
 16 #include <cctype>
 17 #include <cassert>
 18 using namespace std;
 19
 20 typedef struct trie_t {
 21     int n;
 22     int next[26];
 23     trie_t() {
 24         n = 0;
 25         memset(next, 0, sizeof(next));
 26     }
 27 } trie_t;
 28
 29 const int maxn = 1e5+5;
 30
 31 trie_t T[maxn];
 32 int L = 0;
 33 char s[maxn];
 34 int n, m;
 35
 36 int newTrie() {
 37     return ++L;
 38 }
 39
 40 void create(char *s, int rt) {
 41     int p = rt;
 42     int i = 0, id;
 43
 44     while (s[i]) {
 45         id = s[i] - 'a';
 46         if (T[p].next[id] == 0) {
 47             T[p].next[id] = ++L;
 48             ++T[p].n;
 49         }
 50         p = T[p].next[id];
 51         ++i;
 52     }
 53 }
 54
 55 int dfs(int rt) {
 56     int i;
 57     int st = 0;
 58
 59     if (T[rt].n == 0)
 60         return 2;
 61
 62     for (i=0; i<26; ++i) {
 63         if (T[rt].next[i])
 64             st |= dfs(T[rt].next[i]);
 65     }
 66     switch(st) {
 67     case 0:
 68         return 3;
 69     case 1:
 70         return 2;
 71     case 2:
 72         return 1;
 73     case 3:
 74         return 0;
 75     default:
 76         return 0;
 77     }
 78 }
 79
 80
 81 int main() {
 82     int i, j, k;
 83
 84     #ifndef ONLINE_JUDGE
 85         freopen("data.in", "r", stdin);
 86         freopen("data.out", "w", stdout);
 87     #endif
 88
 89     scanf("%d %d", &n, &m);
 90     // build trie
 91     for (i=0; i<n; ++i) {
 92         scanf("%s", s);
 93         create(s, 0);
 94     }
 95     // get the key point
 96     int st = 0;
 97     for (i=0; i<26; ++i) {
 98         if (T[0].next[i])
 99             st |= dfs(T[0].next[i]);
100     }
101
102     if (st == 3) {
103         puts("First");
104         return 0;
105     } else if (st == 0) {
106         puts("Second");
107         return 0;
108     }
109     if (st == 1) {
110         puts("Second");
111         return 0;
112     }
113     if (m & 1) {
114         puts("First");
115     } else {
116         puts("Second");
117     }
118
119     #ifndef ONLINE_JUDGE
120         printf("time = %d.\n", (int)clock());
121     #endif
122
123     return 0;
124 }

转载于:https://www.cnblogs.com/bombe1013/p/4458105.html

【CF】556D A Lot of Games相关推荐

  1. 【cf】Codeforces 题解等汇总

    [cf]Codeforces Round #774 (Div. 2) 前4题 [cf]Codeforces Round #774 (Div. 2) 前4题_legend_yst的博客-CSDN博客 [ ...

  2. 【CodeForces】445B A Lot of Games 字典树博弈

    传送门:[CodeForces]445B  A Lot of Games 题目大意:两人一起构造一个串,每人每次向串的末尾放一个字母,必须保证放了这个字母后能够成所给的N个串的前缀,如果某个人不能放时 ...

  3. cf端游界面更新显示服务器繁忙,【CF】UI界面更新了,那玩家期待已久的经典服务器呢?...

    原标题:[CF]UI界面更新了,那玩家期待已久的经典服务器呢? Hello,大家好,我是你们的灵狐姐,相信小伙伴们都知道新版本更新的所有内容了!目前体验服已经正式上线,相信不久后正服也是马上更新了!本 ...

  4. 【cf】Codeforces Round #784(Div 4)

    由于一次比赛被虐得太惨,,生发开始写blog的想法,于是便有了这篇随笔(找了个近期的cf比赛练练手(bushi))第一次写blog,多多包涵. 第二场cf比赛,第一场打的Div2,被虐太惨,所以第二场 ...

  5. 【CF】474E Pillars

    H的范围是10^15,DP方程很容易想到.但是因为H的范围太大了,而n的范围还算可以接受.因此,对高度排序排重后.使用新的索引建立线段树,使用线段树查询当前高度区间内的最大值,以及该最大值的前趋索引. ...

  6. 【CF】142 Div.1 B. Planes

    SPFA.注意状态转移条件,ans的求解需要在bfs中间求解.因为只要到了地点n,则无需等待其他tourist. 还是蛮简单的,注意细节. 1 /* 229B */ 2 #include <io ...

  7. 【CF】304 E. Soldier and Traveling

    基础网络流,增加s和t,同时对于每个结点分裂为流入结点和流出结点.EK求最大流,判断最大流是否等于当前总人数. 1 /* 304E */ 2 #include <iostream> 3 # ...

  8. 【CF】3B Lorry

    这道题目网上有几个题解,均有问题.其实就是简单的贪心+排序,没必要做的那么复杂. 一旦tot+curv > v时,显然curv==2, 有三种可能: (1)取出最小的curv==1的pp,装入当 ...

  9. 【CF】Codeforces 1702F

    Equate Multisets 题目描述 Multiset -is a set of numbers in which there can be equal elements, and the or ...

最新文章

  1. 两个苹果手机怎么传通讯录_苹果手机通讯录丢失怎么恢复?货真价实的通讯录恢复技巧...
  2. 报错解决: error: ‘writev’ was not declared in this scope
  3. 02.规划过程组表格-采购管理计划
  4. 特征选择 回归_如何执行回归问题的特征选择
  5. 程序人生:搜索引擎被禁用,你还会写代码吗?
  6. html 转换为cshtml,使用Html而不是csHtml
  7. [html] 说说你对短链接的理解,它有什么应用场景呢?
  8. 【报告分享】美好城市指数:短视频与城市繁荣关系白皮书.pdf(附下载链接)...
  9. Windows Workflow Foundation 培训资源
  10. 计算机视觉实战 (一) 开个视觉实战专栏
  11. pip安装tensorflow_Tensorflow源代码编译踩坑若干
  12. 怎么设置计算机 图标显示桌面快捷方式,如何设置显示桌面快捷键 设置显示桌面快捷键方法【图文】...
  13. Beyong Compare过期
  14. 单词拼写检查之cutoff距离
  15. 派件系统c语言实验报告,物流规划与优化选址实验报告.doc
  16. MySQL数据表插入数据及增加语句
  17. 递归算法和文件队列算法----实现多级文件夹的遍历,删除和复制操作
  18. 讲座回顾丨5G的全新可能:基于Smart Edge Open和EdgeX构建5G MEC
  19. 大众点评数据采集分析
  20. hive、impala的客户端,cli、beeline、WebHCat

热门文章

  1. python怎么安装jieba库-python环境jieba分词的安装
  2. LeetCode week252
  3. QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connect
  4. Hadoop on Mac with IntelliJ IDEA - 3 解决MRUnit - No applicable class implementing Serialization问题...
  5. 练习题 James and Dominoes
  6. VS2005的Command Window 调试命令的总结(转载)
  7. Python基础-socket编程
  8. django(未解决的问题)
  9. Android之线程池深度剖析
  10. hdoj5317【素数预处理】