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轮游戏,最后胜利的人是谁. 思路: 很 ...
随机推荐
- easyUI treeGrid 的小例子
今天由于业务的需要,于是采用了easyui的的treeGrid控件. <table title="Folder Browser" class="easyui-tre ...
- 2015第27周三Java内存模型
自己写的代码,6个月不看也是别人的代码,自己学的知识也同样如此,学完的知识如果不使用或者不常常回顾,那么还不是自己的知识. 要认识java线程安全,必须了解两个主要的点:java的内存模型,java的 ...
- delphi7调用java写的webservice,在调用的时候弹出“wssecurityhandler:request does not contain required security header”
delphi7调用java编写的webservice问题我用delphi7调用java写的webservice,在调用的时候弹出“wssecurityhandler:request does not ...
- Android视图框架
Android视图框架 Android的UI系统是android应用系统框架最核心,最基础的内容! 1. Android视图系统.层次关系 Android应用设计和Web应用设计类似,也分前端和后端设 ...
- Android视频录制
public class MainActivity extends Activity { private MediaRecorder videoRecorder=null; private Butto ...
- Android中程序包的相关操作
//获取系统中已经安装的应用程序 List<PackageInfo> packageinfos=this.getPackageManager().getInstalledPackages( ...
- P - Atlantis - hdu1542(求面积)
题意:rt 求面积......不计算重复面积(废话..)hdu1255 的弱化版,应该先做这道题在做那道题的. ******************************************** ...
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...
- 安装nodejs 后运行 npm 命令无响应处理方法
安装和卸载过nodejs, 也编辑过 C:\Users\{账户}\下的.npmrc文件. 再全新安装nodejs ,运行npm 命令,无响应. 处理方法,删除C:\Users\{账户}\下的.npmr ...
- Collision使用 获取其组件执行变色操作
using UnityEngine; using System.Collections; public class CyCollision : MonoBehaviour { void OnColli ...