8VC Venture Cup 2017 - Elimination Round B. PolandBall and Game【思维+模拟】
来源:互联网 发布:pitstop汉化破解版mac 编辑:程序博客网 时间:2024/04/28 05:07
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
The first input line contains two integers n andm (1 ≤ n, m ≤ 103) — number of words PolandBall and EnemyBall know, respectively.
Then n strings follow, one per line — words familiar to PolandBall.
Then m strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a word more than once (strings are unique), but some wordscan be known by both players.
Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
5 1polandballisacoolcharacternope
YES
2 2kremowkawadowickakremowkawiedenska
YES
1 2aab
NO
In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only saywiedenska. PolandBall says wadowicka and wins.
题目大意:
现在第一个人知道N个单词,第二个人知道M个单词,两个人轮流说单词,第一个人先手,要求不能说之前说过的单词。问第一个人能不能赢。当轮到一个人的时候他说不粗来单词,那么他就输了。
思路:
1、问题关键点就在于统计第一个人能够说多少个单词a,第二个人能够说多少个单词b.如果a>b,那么第一个人就可以获胜。
2、那么问题的难点就在于处理两个人都认识的单词上来。
我们用map记录第一个人认识的单词,对于第二个人认识的单词,进行判断,一共两个人有多少个单词是重复认识的(两个人都认识);
那么我们假设两个人都想让自己赢,那么肯定是先互相说重复认识的单词,那么如果重复单词的数量为奇数,那么相当于第一个人能够说a+1-重复单词个数个单词,第二个人能够说b-重复单词个数个单词。同理,如果重复单词的数量为偶数,那么那么相当于第一个人能够说a-重复单词个数个单词,第二个人能够说b-重复单词个数个单词
3、接下来我们判断a和b的大小即可。
Ac代码:
#include<stdio.h>#include<string.h>#include<string>#include<iostream>#include<map>#include<set>using namespace std;int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { map<string ,int >s; char name[1005]; for(int i=0;i<n;i++) { scanf("%s",name); s[name]++; } int chongfu=0; for(int j=0;j<m;j++) { scanf("%s",name); if(s[name]>0) { chongfu++; } } int a=n-chongfu+chongfu%2; int b=m-chongfu; if(a>b) { printf("YES\n"); } else printf("NO\n"); }}
- 8VC Venture Cup 2017 - Elimination Round B. PolandBall and Game【思维+模拟】
- 8VC Venture Cup 2017 - Elimination Round D. PolandBall and Polygon【思维+树状数组】好题
- 8VC Venture Cup 2017 - Elimination Round E. PolandBall and White-Red graph【枚举思维】
- codeforces 8VC Venture Cup 2017 - Elimination Round D PolandBall and Polygon
- Codeforces 8VC Venture Cup 2017 - Elimination Round D.PolandBall and Polygon
- 8VC Venture Cup 2017 - Elimination Round A. PolandBall and Hypothesis【水题】
- 8VC Venture Cup 2017 - Elimination Round C. PolandBall and Forest【并查集】
- 8VC Venture Cup 2017 - Elimination Round D. PolandBall and Polygon 树状数组+几何
- 8VC Venture Cup 2017 - Elimination Round D. PolandBall and Polygon
- 8VC Venture Cup 2017 - Elimination Round(A+B)
- 8VC Venture Cup 2017 - Elimination Round
- 8VC Venture Cup 2017 - Elimination RoundC. PolandBall and Forest(并查集)
- Codeforces 8VC Venture Cup 2017 - Elimination Round
- 8VC Venture Cup 2017 - Elimination Round (先更A-B-C题)
- 8VC Venture Cup 2016 - Elimination Round-A. Robot Sequence(模拟)
- 8VC Venture Cup 2016 - Elimination Round B. Cards (隐式图DFS)
- 8VC Venture Cup 2016 - Elimination Round-B. Cards(暴力)
- 8VC Venture Cup 2016 - Elimination Round B. Cards(分类讨论)
- 深入理解Spring MVC 思想
- Linux 让进程在后台可靠运行的几种方法
- springMvc +Jdbctemplate+分页
- 产品发展的不同阶段,如何利用数据来驱动产品运营?
- 解决Mac版android studio代码svn不能提交
- 8VC Venture Cup 2017 - Elimination Round B. PolandBall and Game【思维+模拟】
- 承载网之传输
- RxJava的详细介绍
- 剑指offer(19)-第一个只出现一次的字符
- 【转】苹果计划推出原创视频内容
- 阿里云CentOS pdf2htmlEX的安装
- 【c++】类型转换
- mac apache terminal启动 停止 重启
- Unity3D FPS帧数修改