题目大意:

有两个人轮流说单词,已经说过的单词不能再说。给出两人掌握的不同的单词,两人可能掌握相同的单词,但是这个单词也只能说一边。问在两人都是最优策略下先手是否必胜.

题解:

我们发现最优策略一定是先说两人都掌握的单词。
所以我们求出所有同时被掌握的单词
然后根据这种单词的奇偶性来判断即可.

求的时候写了个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;
}

转载于:https://www.cnblogs.com/Skyminer/p/6358057.html

Codeforces 755B. PolandBall and Game 贪心相关推荐

  1. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  2. Codeforces 671E Organizing a Race (贪心、线段树)

    题目链接 https://codeforces.com/contest/671/problem/E 题解 完全不会做--基本是抄lk的代码 ruogu的题解: https://www.luogu.co ...

  3. CodeForces - 1529E Trees of Tranquillity(贪心+线段树)

    题目链接:https://vjudge.net/problem/CodeForces-1529E 题目大意:给出两棵根节点为 111 的树,分别称为 AAA 树和 BBB 树,现在通过两棵树可以构造出 ...

  4. [CodeForces 1603C] Extreme Extension(贪心 + 数论分块优化dp)

    problem CodeForces solution observation1:\text{observation1}:observation1: 对于一个非空子段 [l,r][l,r][l,r], ...

  5. codeforces 416C C. Booking System(贪心)

    题目链接: codeforces 416C 题目大意: 给出n个请求,每个请求包括客人数量和支付金额,再给出m个桌子,包括桌子大小,问如何安排才能最大盈利.给出最大盈利和一个能够最大盈利的方案. 题目 ...

  6. Codeforces 540B School Marks 【贪心构造】

    题目链接:Codeforces 540B School Marks Little Vova studies programming in an elite school. Vova and his c ...

  7. CodeForces 508E Arthur and Brackets 贪心

    题目: E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input s ...

  8. Codeforces 797C Minimal string【贪心】

    题意: 给出了字符串s的内容,字符串t,u初始默认为空,允许做两种操作: 1.把s字符串第一个字符转移到t字符串最后. 2.把t字符串最后一个字符转移到u字符串最后. 最后要求s.t字符串都为空,问u ...

  9. codeforces 719C (复杂模拟-四舍五入-贪心)

    题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑... 转载于:https://www.cnblogs.com/A--Q/p/5 ...

最新文章

  1. oracle-单行函数
  2. 司爱侠计算机英语教程第五版翻译,计算机英语教程 教学课件 作者 司爱侠 张强华 参考译文.doc...
  3. 客座编辑:季统凯(1972-),男,博士,中国科学院云计算产业技术创新与育成中心研究员、主任。...
  4. 2019年7月全国程序员工资统计
  5. 《天天数学》连载08:一月八日
  6. 潜谈IT从业人员在传统IT和互联网之间的择业问题(上)-传统乙方形公司
  7. 【less-1】基于SQLI的SQL字符型报错注入
  8. 这是一款仅针对「中国网民」的勒索软件(含源码下载)
  9. 知更鸟begin主题常见问题
  10. 360html5播放加速,总结:没有讨论加速问题,“视频快速观看”完全支持360种浏览器...
  11. WordPress去掉分类链接中category目录的两种方法
  12. python 抓取豆瓣一拍一所有妹子客片
  13. Postgresql源码(33)Btree索引读——整体流程_bt_first
  14. 毕业相关-自动问答综述
  15. C语言——医院挂号系统(队列)
  16. 14、MyBatis-Plus入门到进阶
  17. jstree刷新数据
  18. 论文的总体结构及质量控制
  19. IDEA集成scala
  20. win10夜间模式无效替代解决方案

热门文章

  1. java singleton 多线程_Java创建线程安全的单例singleton
  2. c++ sendmessage 鼠标 坐标是相对自身吗_CAD大家都说会:这些知识不知道,你敢说会CAD吗?...
  3. CSS3 box-orient box-direction box-align box-flex box-pack
  4. ViewTreeObserver
  5. Android学习笔记之Fragment的两种使用方法
  6. 找出数组中两个只出现一次的数字
  7. 用Arduino检测环境中的温湿度
  8. linux中crontab命令的基本用法
  9. Java之socket编程
  10. python六十: __doc__属性