【codeforces 755B】PolandBall and Game

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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.

【题目链接】:http://codeforces.com/contest/755/problem/B

【题解】

显然两个人都肯定先争取中间重复那段先拿;
每个人每次只能拿一个单词;
则为奇数的话对第一个人来说有利;
然后去掉重复的中间那段;
设去掉重复后两人的单词量为x,y
则如果之前重复个数为奇数
x=x+1;
偶数的话则不用做处理;
然后比较x,y;
相同的话是第一个人输,
因为每次第一个人拿完之后,第二个人都比第一个人的单词量多;

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int MAXN = 110;

int n,m;
map <string,int> dic;

int main()
{
    //freopen("F:\rush.txt","r",stdin);
    rei(n);rei(m);
    rep1(i,1,n)
    {
        string s1;
        cin >> s1;
        dic[s1] = 1;
    }
    int cnt = 0;
    rep1(i,1,m)
    {
        string s2;
        cin >> s2;
        if (dic[s2])
            cnt++;
    }
    if (cnt&1)
    {
        n-=cnt;m-=cnt;
        n++;
    }
    else
    {
        n-=cnt;m-=cnt;
    }
    if (n>m)
        puts("YES");
    else
        puts("NO");
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7626716.html