您的位置:首页 > 其它

第一周第一篇

2018-01-20 15:19 197 查看
题目链接

C - PolandBall and Game

题目大义

有两个人玩猜字游戏,第一个先手,他们不能说同样的单词,谁先没词可说谁就输,如果第一个人能赢,则输出“YES”,否则输出NO。

数据范围

1 ≤ n, m ≤ 1e3

字符串长度不超过500

解题思路

首先用map记录第一个人会的单词,输入第二个人会的单词的时候,看map有没有被标记过,如果被标记过则用cnt++来表示他们都会的单词个数,如果cnt为奇数,则第一个人会的单词等价于n - cnt + 1, 第二个人会的单词个数等价于 m-cnt, 如果cnt为偶数,则第一个和第二个会的单词都等价于自身会的单词-cnt。

AC代码

#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>
using namespace std;

int main(){
int n, m;
while(cin >> n >> m){
map<string, int> f;
int num1 = 0, num2 = 0, cnt = 0;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
f[s] = 1;
}
for (int i = 1; i <= m; i++) {
string s;
cin >> s;
if(f[s]) cnt++;
else f[s] = 1;
}
if(cnt & 1){
n = n-cnt+1;
m -= cnt;
}
else {
n -= cnt;
m -= cnt;
}
//     cout << cnt << endl;
if(n > m) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vj寒假训练题