构建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[];
  23. trie_t() {
  24. n = ;
  25. memset(next, , sizeof(next));
  26. }
  27. } trie_t;
  28.  
  29. const int maxn = 1e5+;
  30.  
  31. trie_t T[maxn];
  32. int L = ;
  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 = , id;
  43.  
  44. while (s[i]) {
  45. id = s[i] - 'a';
  46. if (T[p].next[id] == ) {
  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 = ;
  58.  
  59. if (T[rt].n == )
  60. return ;
  61.  
  62. for (i=; i<; ++i) {
  63. if (T[rt].next[i])
  64. st |= dfs(T[rt].next[i]);
  65. }
  66. switch(st) {
  67. case :
  68. return ;
  69. case :
  70. return ;
  71. case :
  72. return ;
  73. case :
  74. return ;
  75. default:
  76. return ;
  77. }
  78. }
  79.  
  80. int main() {
  81. int i, j, k;
  82.  
  83. #ifndef ONLINE_JUDGE
  84. freopen("data.in", "r", stdin);
  85. freopen("data.out", "w", stdout);
  86. #endif
  87.  
  88. scanf("%d %d", &n, &m);
  89. // build trie
  90. for (i=; i<n; ++i) {
  91. scanf("%s", s);
  92. create(s, );
  93. }
  94. // get the key point
  95. int st = ;
  96. for (i=; i<; ++i) {
  97. if (T[].next[i])
  98. st |= dfs(T[].next[i]);
  99. }
  100.  
  101. if (st == ) {
  102. puts("First");
  103. return ;
  104. } else if (st == ) {
  105. puts("Second");
  106. return ;
  107. }
  108. if (st == ) {
  109. puts("Second");
  110. return ;
  111. }
  112. if (m & ) {
  113. puts("First");
  114. } else {
  115. puts("Second");
  116. }
  117.  
  118. #ifndef ONLINE_JUDGE
  119. printf("time = %d.\n", (int)clock());
  120. #endif
  121.  
  122. return ;
  123. }

【CF】556D A Lot of Games的更多相关文章

  1. 【CF】438E. The Child and Binary Tree

    http://codeforces.com/contest/438/problem/E 题意:询问每个点权值在 $c_1, c_2, ..., c_m$ 中,总权值和为 $s$ 的二叉树个数.请给出每 ...

  2. 【CF】148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<= ...

  3. 【CF】328 D. Super M

    这种图论题已经变得简单了... /* D */ #include <iostream> #include <string> #include <map> #incl ...

  4. 【CF】323 Div2. D. Once Again...

    挺有意思的一道题目.考虑长度为n的数组,重复n次,可以得到n*n的最长上升子序列.同理,也可以得到n*n的最长下降子序列.因此,把t分成prefix(上升子序列) + cycle(one intege ...

  5. 【CF】7 Beta Round D. Palindrome Degree

    manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件. /* 7D */ #include &l ...

  6. 【CF】86 B. Petr#

    误以为是求满足条件的substring总数(解法是KMP分别以Sbeg和Send作为模式串求解满足条件的position,然后O(n^2)或者O(nlgn)求解).后来发现是求set(all vali ...

  7. 【CF】121 Div.1 C. Fools and Roads

    题意是给定一棵树.同时,给定如下k个查询: 给出任意两点u,v,对u到v的路径所经过的边进行加计数. k个查询后,分别输出各边的计数之和. 思路利用LCA,对cnt[u]++, cnt[v]++,并对 ...

  8. 【CF】310 Div.1 C. Case of Chocolate

    线段树的简单题目,做一个离散化,O(lgn)可以找到id.RE了一晚上,额,后来找到了原因. /* 555C */ #include <iostream> #include <str ...

  9. 【CF】110 Div.1 B. Suspects

    这题目乍眼一看还以为是2-sat.其实很水的,O(n)就解了.枚举每个人,假设其作为凶手.观察是否满足条件.然后再对满足的数目分类讨论,进行求解. /* 156B */ #include <io ...

随机推荐

  1. Js完美验证15/18身份证,Js验证身份证,支持15/18位

    Js完美验证15/18身份证,Js验证身份证,支持15/18位 >>>>>>>>>>>>>>>>> ...

  2. 使用Android Studio时so文件打包不到APK中

    1,需要在build中添加如下配置,这是必备的 Android {   sourceSets {       main {           jniLibs.srcDirs = ['libs']   ...

  3. 免费的手机号码归属地查询API接口文档

    聚合数据手机号码归属四查询API接口,根据手机号码或手机号码的前7位,查询手机号码归属地信息,包括省份 .城市.区号.邮编.运营商和卡类型. 通过链接https://www.juhe.cn/docs/ ...

  4. update inner join

    string sql = @"update a set a.M_ParentID=b.M_ParentID, a.M_Name=b.M_Name, a.M_Seq=b.M_Seq from ...

  5. C#百分比式布局

    图一:原始窗口 图二:放大窗口 实现:窗体内添加一个panel1(Dock:Left),在窗体空余部分添加第二个panel2(Dock:Fill),窗体分为两部分. 在panel2内添加一个panel ...

  6. java反射的应用+mybatis+spring动态生成数据库表

    最近接触了一个类似于代码生成工具的活.思路是,通过java的反射机制得到类的字段和字段类型, 从而可以创建一个map集合存储表名(由类名决定的特殊结构字符串),表字段(由类变量确定),表字段类型(由变 ...

  7. Ubuntu Server下建立VPN服务器 pptp 模式的方法

    对于想要在外部访问内部的网络,除了在防火墙上开启相应服务器所对应的端口,最好的方法应该是建立VPN-Server,使得用户可以在外网任何一台计算机上拨入到内网中进行操作,而且VPN可以记录详细的日志, ...

  8. shell脚本学习之$0,$?,$!等的特殊用法

    变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 ...

  9. Oracle11g服务及实例

    1Orcl服务说明 1) Oracle ORCL VSS Writer Service:Oracle卷映射拷贝写入服务,VSS(Volume Shadow Copy Service)能够让存储基础设备 ...

  10. hdoj (1162) 最小生成树

    Problem B Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...