题目链接

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. Qt连接sql server数据库遇到的问题

        在QT中使用addDataBase添加一个数据库连接,其中第一个参数应该填入使用数据库驱动的类型,如QMYSQL.QSQLLITE.QSQLPSSQL等. QSqlDatabase QSqlD ...

  2. [转].NET4.0新特性集合贴

    vs2010正式版4月12日发布了,前几天我也下了一个,但这几天都没有时间好好试用一下,今天针对C#语言的新特性使用了一下,感觉还不错,有几个新特性和大家分享一下,希望我没有太火星…… 一.新关键词— ...

  3. 监听事件动态改变dom状态

    html代码: <table class="table table-striped"> <thead> <tr> <th>分类ID& ...

  4. LUOGU P1514 引水入城 (bfs)

    传送门 解题思路 拉了很长的战线,换了好几种写法终于过了..首先每个蓄水场一定是对沙漠造成连续一段的贡献,所以可以$bfs$出每种状态,然后做一次最小区间覆盖,但这样的复杂度有点高.就每次只搜那些比左 ...

  5. vagrant网站中box下载方法

    假设需要下载Laravel/homestead这个包. 首先定位到地址:https://app.vagrantup.com/laravel/boxes/homestead/versions/8.0.0 ...

  6. poj 2774 字符串哈希求最长公共子串

    Long Long Message #include <iostream> #include <algorithm> #include <cstdio> #incl ...

  7. Android基础控件TextView

    1.常用属性 <TextView android:id="@+id/text11" //组件id android:layout_width="match_paren ...

  8. CF 1281B Azamon Web Services

    原题链接:http://codeforces.com/problemset/problem/1281/B 题目大意: 给你两个字符串 s 和 c ,最多经过一次变换,使s的字典序小于c,输出变换后的s ...

  9. Mybatis-构建 SqlSessionFactory

    从 XML 中构建 SqlSessionFactory 每 一 个 MyBatis 的 应 用 程 序 都 以 一 个 SqlSessionFactory 对 象 的 实 例 为 核 心 . SqlS ...

  10. ElasticSearch入门介绍之安装部署(二)

    散仙,在上篇文章对ElasticSearch整体入门作了个介绍,那么本篇我们来看下,如何安装,部署es,以及如何安装es的几个比较常用的插件. es的安装和部署,是非常简单方便的,至少这一点散仙在es ...