第一周第一篇
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代码
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; }
相关文章推荐
- 学习笔记 第一周 第一篇
- #OSG+VS#03第一周
- 博客第一篇,大白在努力~
- 利用redis做频率限制第一篇
- 算法分析与设计第一周习题:2. Add Two Numbers
- 第一篇 channel和channelartlist标签详解
- Autofac 解释第一个例子 《第一篇》
- 第一周
- 秒杀多线程第一篇 CreateThread与_beginthreadex本质区别
- 大数据第一周总结
- 记:第一篇CSDNBLOG
- DuiLib——第一篇UIManager
- 第一篇博客
- 20155333 2016-2017-2 《Java程序设计》第一周学习总结
- 我的第一篇博客
- Python实战_1_第一周_第二节练习项目:爬取商品信息
- 20155334 2016-2017-2 《Java程序设计》第一周学习总结
- 90后嵌入式软件开发生涯 第一篇(am335x LCD 驱动移植)
- wxy第一篇博客
- 本人第一篇博客