8VC Venture Cup 2017 - Elimination Round B. PolandBall and Game【思维+模拟】

来源:互联网 发布:pitstop汉化破解版mac 编辑:程序博客网 时间:2024/04/28 05:07

B. PolandBall and Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 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.

Output

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

Examples
Input
5 1polandballisacoolcharacternope
Output
YES
Input
2 2kremowkawadowickakremowkawiedenska
Output
YES
Input
1 2aab
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 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");    }}







0 0