题目链接

B. A Lot of Games
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players.

Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the resulting word must be prefix of at least one string from the group. A player loses if he cannot move.

Andrew and Alex decided to play this game k times. The player who is the loser of the i-th game makes the first move in the (i + 1)-th game. Guys decided that the winner of all games is the player who wins the last (k-th) game. Andrew and Alex already started the game. Fedor wants to know who wins the game if both players will play optimally. Help him.

Input

The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 109).

Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn't exceed 105. Each string of the group consists only of lowercase English letters.

Output

If the player who moves first wins, print "First", otherwise print "Second" (without the quotes).

Sample test(s)
input
2 3
a
b
output
First
input
3 1
a
b
c
output
First
input
1 2
ab
output
Second
Trie树存储字符串,我们需要保存到达某个结点时是否必胜或者是否存在必败态。
win[u]表示在结点u是否必胜, lose[u]表示在结点u是否存在必败态。
Accepted Code:
 /*************************************************************************
> File Name: D.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年08月13日 星期三 14时10分37秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ const int maxn = ;
int ch[maxn][]; struct Trie {
int sz;
Trie() {
memset(ch[], , sizeof(ch[]));
sz = ;
}
void insert(char *s);
void dfs(int u);
}; inline void Trie::insert(char *s) {
int u = , n = (int)strlen(s);
for (int i = ; i < n; i++) {
int id = s[i] - 'a';
if (!ch[u][id]) {
memset(ch[sz], , sizeof(ch[sz]));
ch[u][id] = sz++;
}
u = ch[u][id];
}
} bool win[maxn], lose[maxn];
inline void Trie::dfs(int u) {
bool flag = false;
for (int i = ; i < ; i++) if (ch[u][i]) {
flag = true;
int v = ch[u][i];
dfs(v);
if (!win[v]) win[u] = true;
if (!lose[v]) lose[u] = true;
}
if (!flag) lose[u] = true;
} char str[maxn];
int main(void) {
int n, k;
Trie A;
scanf("%d %d", &n, &k);
while (n--) scanf("%s", str), A.insert(str);
memset(win, false, sizeof(win));
memset(lose, false, sizeof(lose));
A.dfs();
if ((win[] && lose[]) || (win[] && k&)) puts("First");
else puts("Second"); return ;
}
												

Codeforces 455B的更多相关文章

  1. Codeforces 455B A Lot of Games(字典树+博弈)

    题目连接: Codeforces 455B A Lot of Games 题目大意:给定n.表示字符串集合. 给定k,表示进行了k次游戏,然后是n个字符串.每局開始.字符串为空串,然后两人轮流在末尾追 ...

  2. Codeforces 455B A Lot of Games

    http://codeforces.com/contest/455/problem/B 题目大意: 给出n个字符串,进行k次游戏,每次游戏输家下次作为先手,游戏规则为每次放一个字母,导致当前构造的字符 ...

  3. Codeforces 455B A Lot of Games:博弈dp【多局游戏】

    题目链接:http://codeforces.com/problemset/problem/455/B 题意: 给你n个字符串,然后进行k局游戏. 每局游戏开始有一个空串,然后双方轮流给这个串的末尾添 ...

  4. codeforces 455B A Lot of Games(博弈,字典树)

    题目 参考自博客:http://blog.csdn.net/keshuai19940722/article/details/38455269 //字典树,博弈 根据当前节点的后续来确定当前节点的状态, ...

  5. CodeForces 455B A Lot of Games (博弈论)

    A Lot of Games 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/J Description Andrew, Fedo ...

  6. Codeforces 455B A Lot of Games 字典树上博弈

    题目链接:点击打开链接 题意: 给定n个字符串,k局游戏 对于每局游戏,2个玩家轮流给一个空串加入一个小写字母使得加完后的字符串不是n个字符串的前缀. 输家下一轮先手 问是先手必胜还是后手必胜 思路: ...

  7. ACM 博弈(难)题练习 (第一弹)

    第二弹: 套路&&经验总结: 1. N堆***的游戏,一般可以打表找SG函数的规律.比如CodeForces 603C 2.看起来是单轮的游戏,实际上可能拆分成一些独立的子游戏.比如C ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. [USACO2005 nov] Grazing on the Run【区间Dp】

    Online Judge:bzoj1742,bzoj1694 Label:区间Dp 题目描述 John养了一只叫Joseph的奶牛.一次她去放牛,来到一个非常长的一片地,上面有N块地方长了茂盛的草.我 ...

  2. leetcode-106-从中序和后序遍历构造二叉树

    题目描述: 方法一:O(n) O(n) class Solution: def buildTree(self, inorder: List[int], postorder: List[int]) -& ...

  3. 【JZOJ3303】城市规划

    description 刚刚解决完电力网络的问题, 阿狸又被领导的任务给难住了. 刚才说过, 阿狸的国家有n 个城市, 现在国家需要在某些城市对之间建立一些贸易路线, 使得整个国家的任意两个城市都直接 ...

  4. ThinkPHP 删除数据

    ThinkPHP删除数据使用delete方法,例如: 直线电机价格 $Form = M('Form'); $Form->delete(5); 表示删除主键为5的数据,delete方法可以删除单个 ...

  5. Python-函数基础(2)

    目录 可变长参数 形参 实参 函数对象 函数嵌套 名称空间与作用域 名称空间 内置名称空间 局部名称空间 全局名称空间 执行顺序 搜索顺序 作用域 全局作用域 局部作用域 global nonloca ...

  6. display和position以及其余标签的使用

    今天主要学习了两大标签display和position:中文名字是显示和位置,这两个元素在前端的学习还是很重要的,因为在css的布局里面会经常用到这两种元素. 还有一些其余的标签例:margin,pa ...

  7. swiper 插件里面嵌套可滚动内容

    在移动端使用swiper的整屏滚动,如果slide里面有滚动内容的话,滚动的时候会整个页面一起滚动,如果想里面的滚动区域单独滚动的话,可以在初始化swiper的时候添加上 noSwipingClass ...

  8. PHPstorm同步服务器代码的缺点---命名空间undefined

      在把一个服务器的代码同步到phpstorm下开发的时候,发现新建的命名空间代码都失效了,然而换到 https://blog.csdn.net/afraid_to_have/article/deta ...

  9. B/S架构及其运行原理

    一. B/S的概念 B/S(Brower/Server,浏览器/服务器)模式又称B/S结构,是Web兴起后的一种网络结构模式.Web浏览器是客户端最主要的应用软件. 这种模式统一了客户端,将系统功能实 ...

  10. 通过Amazon AWS 十分钟搭建私人主机 自由的不要不要的

      首先承认有点标题党了,当时自己搞的时候可不止十分钟,好吧,我承认是坑太多了,所以特意开了一篇博文,就是要准备尝试的和我一样的菜鸟们,可以真正的十分钟搞定.  当然高手可能用不上十分钟. 首先,就是 ...