Codeforces 755B-PolandBall and Game

来源:互联网 发布:纪念碑谷mac版 编辑:程序博客网 时间:2024/05/16 15:33

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 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 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 say wiedenska. PolandBall says wadowicka and wins.


题意:A和B两人每人都熟悉一些单词。A先开始,每人说一个单词,单词不能与两人之前说过的所有单词重复,谁无话可说谁输。两人可能有共同会的单词。

解题思路:因为要让对方尽量无单词可说,所以每个人优先说的都是两人共同会的单词

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <vector>#include <set>#include <map>using namespace std;string a[1100];string b[1100];int main(){    int n, m;    while(~scanf("%d %d",&n,&m))    {        for(int i=0;i<n;i++)            cin>>a[i];        for(int i=0;i<m;i++)            cin>>b[i];        int x=0;        for(int i=0;i<n;i++)            for(int j=0;j<m;j++)                if(a[i]==b[j]) x++;        if(x&1)        {            if(n>m-1) printf("YES\n");            else printf("NO\n");        }        else        {            if(n>m) printf("YES\n");            else printf("NO\n");        }    }    return 0;}
0 0
原创粉丝点击