Codeforces 455B A Lot of Games
http://codeforces.com/contest/455/problem/B
题目大意:
给出n个字符串,进行k次游戏,每次游戏输家下次作为先手,游戏规则为每次放一个字母,导致当前构造的字符串是给定的任意一个字符串的前缀,不能操作时为输,赢得第k次比赛的人会取得最终的胜利,问两人都采取最优策略的情况下,谁会赢得比赛。
思路:
00代表无法控制,10代表胜,01代表必败,11代表能赢能输。
如果能赢能输,那么可以一直控制自己前k-1场输,最后赢。
如果先手输,那么一定输
如果只能赢,那么胜负只与场数的奇偶有关、
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
int ch[][],n,m,sz,f[],root,flag;
char s[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
void insert(){
scanf("%s",s+);
int now=root,len=strlen(s+);
for (int i=;i<=len;i++){
if (ch[now][s[i]-'a']==) ch[now][s[i]-'a']=++sz;
now=ch[now][s[i]-'a'];
}
}
int dfs(int x,int fa){
bool pd=;int ans=;
for (int i=;i<;i++)
if (ch[x][i]){
ans|=dfs(ch[x][i],x)^;
pd=;
}
if (!pd) ans=;
return ans;
}
int main(){
n=read();m=read();
for (int i=;i<=n;i++){
insert();
}
int tmp=dfs(,);
if (tmp==) printf("First");
else
if (tmp==){
if (m%==) printf("First");
else printf("Second");
}
else
printf("Second");
return ;
}
Codeforces 455B A Lot of Games的更多相关文章
- Codeforces 455B A Lot of Games(字典树+博弈)
题目连接: Codeforces 455B A Lot of Games 题目大意:给定n.表示字符串集合. 给定k,表示进行了k次游戏,然后是n个字符串.每局開始.字符串为空串,然后两人轮流在末尾追 ...
- CodeForces 455B A Lot of Games (博弈论)
A Lot of Games 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/J Description Andrew, Fedo ...
- Codeforces 455B A Lot of Games:博弈dp【多局游戏】
题目链接:http://codeforces.com/problemset/problem/455/B 题意: 给你n个字符串,然后进行k局游戏. 每局游戏开始有一个空串,然后双方轮流给这个串的末尾添 ...
- codeforces 455B A Lot of Games(博弈,字典树)
题目 参考自博客:http://blog.csdn.net/keshuai19940722/article/details/38455269 //字典树,博弈 根据当前节点的后续来确定当前节点的状态, ...
- Codeforces 455B A Lot of Games 字典树上博弈
题目链接:点击打开链接 题意: 给定n个字符串,k局游戏 对于每局游戏,2个玩家轮流给一个空串加入一个小写字母使得加完后的字符串不是n个字符串的前缀. 输家下一轮先手 问是先手必胜还是后手必胜 思路: ...
- [codeforces 325]B. Stadium and Games
[codeforces 325]B. Stadium and Games 试题描述 Daniel is organizing a football tournament. He has come up ...
- Codeforces 980 E. The Number Games
\(>Codeforces \space 980 E. The Number Games<\) 题目大意 : 有一棵点数为 \(n\) 的数,第 \(i\) 个点的点权是 \(2^i\) ...
- Codeforces 455B
题目链接 B. A Lot of Games time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 字典树+博弈 CF 455B A Lot of Games(接龙游戏)
题目链接 题意: A和B轮流在建造一个字,每次添加一个字符,要求是给定的n个串的某一个的前缀,不能添加字符的人输掉游戏,输掉的人先手下一轮的游戏.问A先手,经过k轮游戏,最后胜利的人是谁. 思路: 很 ...
随机推荐
- 手机上使用asmack开发xmpp客户端
openfire服务端,smack: 下载地址:http://www.igniterealtime.org/downloads/index.jsp 源代码:http://www.ign ...
- codevs1033 蚯蚓的游戏问题
题目描述 Description 在一块梯形田地上,一群蚯蚓在做收集食物游戏.蚯蚓们把梯形田地上的食物堆积整理如下: a(1,1) a(1,2)…a(1,m) a(2,1) a(2,2) a(2 ...
- Codeforces Round #300 F - A Heap of Heaps (树状数组 OR 差分)
F. A Heap of Heaps time limit per test 3 seconds memory limit per test 512 megabytes input standard ...
- MD中bitmap源代码分析--设置流程
1. 同步/异步刷磁盘 Bitmap文件写磁盘分同步和异步两种: 1) 同步置位:当盘阵有写请求时,对应的bitmap文件相应bit被置位,bitmap内存页被设置了DIRTY标志.而在下发写请求给磁 ...
- 简单的新闻客户端APP开发(DCloud+thinkphp+scrapy)
前端时间花了1个月左右,搞了个新闻APP,功能很简单,就是把页面版的新闻条目定时爬到后台数据库,然后用app显示出来. 1.客户端 使用了DCloud框架,js基本是个新手,从没写过像样的代码,htm ...
- lua面向对象封装及元表(metatable)性能测试
Lua本身是没有面向对象支持的,但面向对象编程在逻辑复杂的大型工程却很有用.于是很多人用Lua本身的数据结构table来模拟面向对象.最简单的一种方法是把对象的方法.成员都放到table中.如: -- ...
- javascript 实现分享功能
1.面向过程分享 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- 数组字符串与指针字符串的区别 char s[]="***" 和char *s="***"的区别
char s[] = "wangshihui"; char *s = "wangshihui"; 皆宣告了s字符串,在C-style string的函数皆可使用 ...
- Sublime Text2 按shift键选择不了的问题
记录下来,免得以后忘了: 今天在Sublime Text 2装了一个ThinkPHP插件之后.发现按shift键+鼠标左键选择不了内容了.原因是ThinkPHP里的热键与系统的有冲突了,须要设置例如以 ...
- [Angular 2] @ViewChild to access Child component's method
When you want to access child component's method, you can use @ViewChild in the parent: Parent Compo ...