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的末尾 ...
随机推荐
- 线性表的链式实现(C++)
相关内容: 线性表的顺序实现 链式实现(C语言) (推荐在GitHub上查看,下面代码只是最初实现,后续如果有修改,由于太麻烦,不会再更改下文,仅仅更新Github上的代码文件) 结点以及链表类的定义 ...
- spark之pycharm开发设置
方法一: __author__ = 'similarface' import os import sys os.environ['SPARK_HOME']="/Users/similarfa ...
- ui-router $transitions 用法
1. //route redirection $transitions.onStart({to: 'manage'}, function (trans) { var params = trans.pa ...
- HTML5开发移动web应用——SAP UI5篇(8)
本次对之前学习的SAP UI5框架知识进行简单小结.以及重点部分知识的梳理. 1.在UI5使用过程中,命名空间的概念非常重要. 2.一般的sap组件引用格式例如以下: sap.ui.define([ ...
- requestWindowFeature使用详解
requestWindowFeature可以设置的值有: // 1.DEFAULT_FEATURES:系统默认状态,一般不需要指定 // 2.FEATURE_CONTEXT_MENU:启 ...
- Selenium3 Python3 Web自动化测试从基础到项目实战之一启动不同的浏览器及配置
在web自动化中目前selenium作为底层的自动化测试是目前运用最广的,但是各个公司都会在这个基础之上进行修改.从今天开始我们就慢慢从low代码一步一步的学习框架知识. 首先当我们测试环境有了之后我 ...
- python文件读写方式
window下换行\r\n linux.unix.mac下都是\n - 以二进制的形式wb写入,同样以二进制的方式读取rb ``` f = open('file name','wb') f.write ...
- 九度OJ 1043:Day of Week(星期几) (日期计算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5349 解决:1923 题目描述: We now use the Gregorian style of dating in Russia. ...
- 【题解】UVA10140 [Prime Distance]
[题解]UVA10140 Prime Distance 哈哈哈哈\(miller-rabbin\)水过去了哈哈哈 还能怎么办呢?\(miller-rabbin\)直接搞.枚举即可,还跑得飞快. 当然此 ...
- yum安装软件出错解决方法
造成yum下载安装时语法出错, 一般是由于python多个版本共存的原因.所以,只需将yum 设置文件固定python 版本,也就是python2 下面的操作能解决版本冲突问题. 1.sudo vim ...