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;
}
转载于:https://www.cnblogs.com/Skyminer/p/6358057.html
Codeforces 755B. PolandBall and Game 贪心相关推荐
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- Codeforces 671E Organizing a Race (贪心、线段树)
题目链接 https://codeforces.com/contest/671/problem/E 题解 完全不会做--基本是抄lk的代码 ruogu的题解: https://www.luogu.co ...
- CodeForces - 1529E Trees of Tranquillity(贪心+线段树)
题目链接:https://vjudge.net/problem/CodeForces-1529E 题目大意:给出两棵根节点为 111 的树,分别称为 AAA 树和 BBB 树,现在通过两棵树可以构造出 ...
- [CodeForces 1603C] Extreme Extension(贪心 + 数论分块优化dp)
problem CodeForces solution observation1:\text{observation1}:observation1: 对于一个非空子段 [l,r][l,r][l,r], ...
- codeforces 416C C. Booking System(贪心)
题目链接: codeforces 416C 题目大意: 给出n个请求,每个请求包括客人数量和支付金额,再给出m个桌子,包括桌子大小,问如何安排才能最大盈利.给出最大盈利和一个能够最大盈利的方案. 题目 ...
- Codeforces 540B School Marks 【贪心构造】
题目链接:Codeforces 540B School Marks Little Vova studies programming in an elite school. Vova and his c ...
- CodeForces 508E Arthur and Brackets 贪心
题目: E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input s ...
- Codeforces 797C Minimal string【贪心】
题意: 给出了字符串s的内容,字符串t,u初始默认为空,允许做两种操作: 1.把s字符串第一个字符转移到t字符串最后. 2.把t字符串最后一个字符转移到u字符串最后. 最后要求s.t字符串都为空,问u ...
- codeforces 719C (复杂模拟-四舍五入-贪心)
题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑... 转载于:https://www.cnblogs.com/A--Q/p/5 ...
最新文章
- oracle-单行函数
- 司爱侠计算机英语教程第五版翻译,计算机英语教程 教学课件 作者 司爱侠 张强华 参考译文.doc...
- 客座编辑:季统凯(1972-),男,博士,中国科学院云计算产业技术创新与育成中心研究员、主任。...
- 2019年7月全国程序员工资统计
- 《天天数学》连载08:一月八日
- 潜谈IT从业人员在传统IT和互联网之间的择业问题(上)-传统乙方形公司
- 【less-1】基于SQLI的SQL字符型报错注入
- 这是一款仅针对「中国网民」的勒索软件(含源码下载)
- 知更鸟begin主题常见问题
- 360html5播放加速,总结:没有讨论加速问题,“视频快速观看”完全支持360种浏览器...
- WordPress去掉分类链接中category目录的两种方法
- python 抓取豆瓣一拍一所有妹子客片
- Postgresql源码(33)Btree索引读——整体流程_bt_first
- 毕业相关-自动问答综述
- C语言——医院挂号系统(队列)
- 14、MyBatis-Plus入门到进阶
- jstree刷新数据
- 论文的总体结构及质量控制
- IDEA集成scala
- win10夜间模式无效替代解决方案
热门文章
- java singleton 多线程_Java创建线程安全的单例singleton
- c++ sendmessage 鼠标 坐标是相对自身吗_CAD大家都说会:这些知识不知道,你敢说会CAD吗?...
- CSS3 box-orient box-direction box-align box-flex box-pack
- ViewTreeObserver
- Android学习笔记之Fragment的两种使用方法
- 找出数组中两个只出现一次的数字
- 用Arduino检测环境中的温湿度
- linux中crontab命令的基本用法
- Java之socket编程
- python六十: __doc__属性