文章标题 Coderforces 755B : PolandBall and Game(水)

时间:2021-08-17 16:33:25

PolandBall and Game

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?

Input
The first input line contains two integers n and m (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 words can be known by both players.

Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.

Output
In a single line of print the answer — “YES” if PolandBall wins and “NO” otherwise. Both Balls play optimally.

Examples
input
5 1
polandball
is
a
cool
character
nope
output
YES
input
2 2
kremowka
wadowicka
kremowka
wiedenska
output
YES
input
1 2
a
a
b
output
NO
Note
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 say wiedenska. PolandBall says wadowicka and wins
题意:有两个人一个知道的单词数为n,另一个知道的单词数为m,然后两个人没人从自己知道的单词说一个,说过的单词不能再说,最后没单词说的人就算输。
分析:先将两个人同样的单词数算出来,然后剩下的单词都是不一样的单词,此时单词数多的就是赢的人。算两个人同样单词数用map映射,有映射过的还出现说明这个是两个人同样的单词。
代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<math.h>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
const int inf = 0x3f3f3f3f;
int n,m;
string P[1005];
string E[1005];
int main ()
{
while (cin>>n>>m){
map<string,int>mp;
int cnt=0;
for (int i=0;i<n;i++){
cin>>P[i];
mp[P[i]]=1;//每次输进来的单词映射,做一个标记
}
for (int i=0;i<m;i++){
cin>>E[i];
if (mp.find(E[i])==mp.end()){//如果这个单词还没出现
mp[E[i]]=1;
}
else {//单词出现过
mp[P[i]]++;
cnt++;//计数+1
}
}
n-=cnt;//将两个人的相同的单词数减去
m-=cnt;
if (cnt%2==1){//如果是单数的说明第二个人少说一次得减去
m--;
}
if (n>m){//最后剩下多的人就是赢家
cout<<"YES"<<endl;
}
else cout<<"NO"<<endl;
}
return 0;
}