codeforces 455B A Lot of Games(博弈,字典树)
参考自博客:http://blog.csdn.net/keshuai19940722/article/details/38455269
//字典树,博弈
根据当前节点的后续来确定当前节点的状态,0是由对手决定,1是只有可能输,2是只有可能赢,3是可以决定自己的胜负。这些状态是要综合所有后续情况确定的。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
int pos=;
string s; struct tt
{
int val,arr[];
tt(){memset(arr,-,sizeof(arr));val=;}
}a[]; void insert(int id,int d)
{
if(d==s.length())return ; int t=s[d]-'a';
if(a[id].arr[t]==-)
a[id].arr[t]=++pos;
insert(a[id].arr[t],d+);
} int solve(int d)
{
int ans=;
int flag=;
for(int i=;i<;i++)
{
if(a[d].arr[i]!=-)
{
flag=;
ans|=solve(a[d].arr[i]);
}
} if(flag)
ans=;
return -ans;
}
int main()
{
int n,m;
cin>> n>>m;
pos=;
while(n--)
{
cin>>s;
insert(, );
}
int ans = - solve(); if(ans==)cout <<"First"<<endl;
else if(ans==||ans==)cout <<"Second"<<endl;
else
{
if(m&)cout <<"First"<<endl;
else cout <<"Second"<<endl;
}
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 字典树上博弈
题目链接:点击打开链接 题意: 给定n个字符串,k局游戏 对于每局游戏,2个玩家轮流给一个空串加入一个小写字母使得加完后的字符串不是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://codeforces.com/contest/455/problem/B 题目大意: 给出n个字符串,进行k次游戏,每次游戏输家下次作为先手,游戏规则为每次放一个字母,导致当前构造的字符 ...
- E - Petya and Exam CodeForces - 832B 字典树+搜索
E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...
- 字典树+博弈 CF 455B A Lot of Games(接龙游戏)
题目链接 题意: A和B轮流在建造一个字,每次添加一个字符,要求是给定的n个串的某一个的前缀,不能添加字符的人输掉游戏,输掉的人先手下一轮的游戏.问A先手,经过k轮游戏,最后胜利的人是谁. 思路: 很 ...
- codeforces 706D (字典树)
题目链接:http://codeforces.com/problemset/problem/706/D 题意:q次操作,可以向多重集中增添,删除,询问异或最大值. 思路:转化为二进制用字典树存储,数字 ...
- [codeforces 325]B. Stadium and Games
[codeforces 325]B. Stadium and Games 试题描述 Daniel is organizing a football tournament. He has come up ...
随机推荐
- Python学习教程(learning Python)--1.2.3 Python格式化输出百分比
在有些情况下,需要百分比输出数据,我们可以继续使用Python内建函数format来实现百分比的数据输出. >>> print(format(0.5236, '.2%')) 其结果如 ...
- Ruby判断文件是否存在
flag = FileTest::exist?("LochNessMonster") flag = FileTest::exists?("UFO") # exi ...
- ThinkPHP目录结构
ThinkPHP框架目录结构 文件路径 文件描述 \index.php 入口文件 \Application 应用目录 \Public 资源文件目录 \ThinkPHP 框架核心目录 \Applic ...
- asp.net实现手机号码归属地查询
protected void Button1_Click(object sender, EventArgs e) { if (Regex.IsMatch(TextB ...
- 分享C#原生ID(流水号)生成功能实现
///, , )).TotalMilliseconds.ToString(")); /// <summary> /// /// </summ ...
- iOS7 隐藏状态栏 hide statusBar
1.调用 [self setNeedsStatusBarAppearanceUpdate]; 2.重载以下函数 - (BOOL)prefersStatusBarHidden{ return _hide ...
- 集成Spring后HibernateTemplate实现分页
spring 整合 hibernate 时候用的 HibernateTemplate 不支持分页,因此需要自己包装一个类进行分页,具体实现如下...使用spring的hibernateTemplate ...
- 百度翻译API
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...
- Careercup - Microsoft面试题 - 5120588943196160
2014-05-10 22:58 题目链接 原题: Three points are given A(x1, y1), B(x2, y2), C(x3, y3). Write a method ret ...
- C Shell 中的特殊变量
恢复 $0,当前脚本的文件名 $n,传递给脚本或函数的参数,n是一个数字,表示第几个参数 $#,传递给脚本或函数的参数个数 $*,传递给脚本或函数的所有参数 $?,函数的返回值 $$,当前shell的 ...