Codeforces 755B. PolandBall and Game 贪心
题目大意:
有两个人轮流说单词,已经说过的单词不能再说。给出两人掌握的不同的单词,两人可能掌握相同的单词,但是这个单词也只能说一边。问在两人都是最优策略下先手是否必胜.
题解:
我们发现最优策略一定是先说两人都掌握的单词。
所以我们求出所有同时被掌握的单词
然后根据这种单词的奇偶性来判断即可.
求的时候写了个Trie...
不过好像直接暴力也可以..
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 1024;
char s[512];
int nodecnt = 0;
int ch[maxn*256][28];
bool flag[maxn*256];
int root = 0;
void insert(char *s){
int n = strlen(s+1);
int nw = root;
for(int i=1;i<=n;++i){
if(ch[nw][s[i] - 'a'] == 0) ch[nw][s[i] - 'a'] = ++nodecnt;
nw = ch[nw][s[i] - 'a'];
}flag[nw] = true;
}
bool find(char *s){
int n = strlen(s+1);
int nw = root;
for(int i=1;i<=n;++i){
if(ch[nw][s[i] - 'a'] == 0) return false;
nw = ch[nw][s[i] - 'a'];
}return flag[nw];
}
int main(){
int n,m;read(n);read(m);
for(int i=1;i<=n;++i){
scanf("%s",s+1);
insert(s);
}
int com = 0;
for(int i=1;i<=m;++i){
scanf("%s",s+1);
if(find(s)) ++com;
}n -= com;m -= com;
if(com&1){
if(n >= m) puts("YES");
else puts("NO");
}else{
if(n > m) puts("YES");
else puts("NO");
}
getchar();getchar();
return 0;
}
Codeforces 755B. PolandBall and Game 贪心的更多相关文章
- CodeForces - 755B PolandBall and Game(博弈)
题意:A和B两人每人都熟悉一些单词.A先开始,每人说一个单词,单词不能与两人之前说过的所有单词重复,谁无话可说谁输.两人可能有共同会的单词. 分析:因为要让对方尽量无单词可说,所以每个人优先说的都是两 ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- codeforces 755F F. PolandBall and Gifts(贪心+多重背包)
题目链接: F. PolandBall and Gifts time limit per test 1.5 seconds memory limit per test 256 megabytes in ...
- 【codeforces 755B】PolandBall and Game
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 755B:PolandBall and Game(map+思维)
http://codeforces.com/problemset/problem/755/B 题意:A可以喊出n个字符串,B可以喊出m个字符串,如果一个字符串之前被喊过,那么它再也不能喊了,A先喊,最 ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- Codeforces Gym 100269E Energy Tycoon 贪心
题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...
- CodeForces 797C Minimal string:贪心+模拟
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...
随机推荐
- 详细解析用Squid实现反向代理的方法
代理服务器是使 用非常普遍的一种将局域网主机联入互联网的一种方式,使用代理上网可以节约紧缺的IP地址资源,而且可以阻断外部主机对内部主机的访问,使内部网主机免受 外部网主机的攻击.但是,如果想让互联网 ...
- ubuntu boost.python
安装boost(未尝试只安装 libboost-python-dev) sudo apt-get install libboost-all-dev 新建hello_ext.cpp,输入以下代码 1 c ...
- 【Linux】 awk应用
1 统计机器上处于不同状态的所有TCP连接的个数(TCP连接是有状态连接,包含SYN_RECV, ESTABLISHED, TIME_WAIT, FIN_WAIT0, FIN_WAIT1等多种状态, ...
- 基于红帽5裁剪一个简单的Linux
HOST:宿主机 Target:目标机 1.基于HOST制作一个简单的可启动的Linux 1.给目标磁盘分区 两个: 在宿主机上:/dev/sdb1,/dev/sdb2 /dev/sdb1挂载到 /m ...
- mvc 各种返回值
一个例子胜过千言万语,直接上代码 SpringMVC的Controller控制器返回值详解 SpringMVC Controller 返回值几种类型 Spring MVC 更灵活的控制 json 返回 ...
- 线程(while 和 if 剖析)
那存钱取钱为例: 要求实现一次存一次取的操作 不可出现连续存或连续取: 如果只有存钱和取钱各自只有一个线程在操作使用 if 的话可以满足要求: package com.thread; /** * 模拟 ...
- servlet3.0 文件上传功能
注意 jsp页面中file选择 的要有属性 name='file' package com.webserver.webservice; import java.io.File; import java ...
- sql查询的日期判断问题
在SQLSERVE中,如果某个数据表的类型被定义成datetime类型,那么数据是包含秒的.这时候如何查询某天的数据呢?新手们可能想:最直接的做法是把时间部分去掉,只取日期部分.于是日期的函数就用上了 ...
- To discount or not to discount in reinforcement learning: A case study comparing R learning and Q learning
https://www.cs.cmu.edu/afs/cs/project/jair/pub/volume4/kaelbling96a-html/node26.html [平均-打折奖励] Schwa ...
- adjA=(detA)A-1
A–>adjA 连续性 反函数