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?
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.
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
5 1
polandball
is
a
cool
character
nope
YES
2 2
kremowka
wadowicka
kremowka
wiedenska
YES
1 2
a
a
b
NO
代码:
#include <iostream> #include <time.h> #include <cstdio> #include <algorithm> #include <cstring> #include <string> #include <vector> #include <set> #include <map> #define LL long long #define MAX 1<<30 #define MIN -1<<30 #define INIT0(a) memset((a), 0, sizeof(a)) using namespace std; const double PI = 3.14159265358979323; const double les = 0.00000005; const long N = 200000; int main(){ // freopen("input1.txt", "r", stdin); // freopen("output1.txt", "w", stdout); int n, m; while(~scanf("%d%d", &n, &m)){ std::map<string, int> s; char word[550]; for (int i = 0; i < n; ++i) { scanf("%s", word); s[word] ++; } int num = 0; for (int i = 0; i < m; ++i) { scanf("%s", word); if (s[word] > 0) { num ++; } } int a = n - num + num%2; int b = m - num; if (a > b) { printf("YES "); }else { printf("NO "); } } return 0; }
附代码:
map example:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <time.h> #include <cstdio> #include <algorithm> #include <cstring> #include <string> #include <vector> #include <set> #include <map> #define LL long long #define MAX 1<<30 #define MIN -1<<30 #define INIT0(a) memset((a), 0, sizeof(a)) using namespace std; const double PI = 3.14159265358979323; const double les = 0.00000005; const long N = 200000; int main(){ // freopen("input1.txt", "r", stdin); // freopen("output1.txt", "w", stdout); std::map<char,int> mymap; // first insert function version (single parameter): mymap.insert ( std::pair<char,int>('a',100) ); mymap.insert ( std::pair<char,int>('z',200) ); std::pair<std::map<char,int>::iterator,bool> ret; ret = mymap.insert ( std::pair<char,int>('z',500) ); if (ret.second==false) { std::cout << "element 'z' already existed"; std::cout << " with a value of " << ret.first->second << ' '; } // second insert function version (with hint position): std::map<char,int>::iterator it = mymap.begin(); mymap.insert (it, std::pair<char,int>('b',300)); // max efficiency inserting mymap.insert (it, std::pair<char,int>('c',400)); // no max efficiency inserting // third insert function version (range insertion): std::map<char,int> anothermap; anothermap.insert(mymap.begin(),mymap.find('c')); // showing contents: std::cout << "mymap contains: "; for (it=mymap.begin(); it!=mymap.end(); ++it) std::cout << it->first << " => " << it->second << ' '; std::cout << "anothermap contains: "; for (it=anothermap.begin(); it!=anothermap.end(); ++it) std::cout << it->first << " => " << it->second << ' '; return 0; }