【Codeforces 755 B PolandBall and Game】

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 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,以及每个人准备的短语,短语不能重复使用,问 PolandBall 是否能win

思路 : 统计每个人相同的短语数,每人可用一半,若为奇数 PolandBall 可多用一句,若 PolandBall 最后可用的短语多者win

AC代码:

#include<bits/stdc++.h>
using namespace std;
char st1[1010][510],st2[1010][510];
int main()
{
    int N,M;
    scanf("%d %d",&N,&M);
    for(int i = 1 ; i <= N; i++)
        scanf("%s",st1[i]);
    for(int i = 1 ; i <= M; i++)
        scanf("%s",st2[i]);
    int ans = 0;
    for(int i = 1 ; i <= N; i++)
        for(int j = 1 ; j <= M; j++)
            if(strcmp(st1[i],st2[j]) == 0)
                ans++;
    N -= ans / 2 ,M -= ans / 2;
    if(ans % 2) M--;
    if(N > M) printf("YES\n");
    else printf("NO\n");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值