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的末尾 ...
随机推荐
- linux下性能监控工具
一. Linux 性能监控的概述 系统由若干子系统构成,通常改动一个子系统有可能影响到另外一个子系统.甚至会导致整个系统不稳定.崩溃. 所以说优化.监測.測试一般是连在一起的,并且是一个循环并且长期 ...
- Synchronized修饰静态变量和普通变量的区别
这里主要涉及到类对象(static方法),对象方法(非static方法) 我们知道,当synchronized修饰一个static方法时,多线程下,获取的是类锁(即Class本身,注意:不是实例): ...
- org hibernate querytimeoutexception
起因 在做Hibernate批量插入时,出现这个错误org.hibernate.QueryTimeoutException: 错误原因是表空间的容量不足,需要加大空间容量:那首先想到的是应该查询其容量 ...
- Silverlight 5 Grid组的MouseLeave响应
用Silverlight 5作个用户控件,即是用Grid画几个格子.分别显示几张透明图片.效果是显示中间那张,点击显示的图片后将其他几张图片一起显示出来,鼠标立马这个用户控件范围后自己主动隐藏点击后显 ...
- 在hibernate3中如何利用HQL语句查询出对象中的部分数据并且返回该对象?
例如现在有一个Customer对象 public class Customer{ private Integer cid; private String cname; private Integer ...
- java多线程那些事之中的一个
1. Callable 接口 获取线程运行状态(get.get(long timeout)),取消线程(cancel(boolean mayinterruptifrunning)).isCance ...
- 【BZOJ1336】[Balkan2002]Alien最小圆覆盖 随机增量法
[BZOJ1336][Balkan2002]Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=10000 ...
- 修改linux的hostname (修改linux系统的IP和hostname)
# vi /etc/sysconfig/networkNETWORKING=yesHOSTNAME=yourname //在这修改hostnameNISDOMAIN=eng-cn.platform.c ...
- JAVA数据类型(转)
java中数据的基本类型分为: 基本数据类型和引用数据类型,对此不多介绍: 接下来讨论一下java中数据类型存储在哪 基本数据类型存储在哪,取决于基本类型在哪声明: 1 ...
- packages/wepy-web/src/wx.js 分析storage 的加载原理 wx.getStorage(OBJECT)
是小程序实例化后 读入内存 还是每次调用从文件系统读取 https://github.com/Tencent/wepy/blob/bd0003dca2bfb9581134e1b05d4aa1d80fc ...