zoukankan      html  css  js  c++  java
  • STL之map

    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

    代码:
    #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:

    #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;
    }
    View Code
  • 相关阅读:
    【XAF】非持久化对象分组和属于不同会话
    【原创】XAF 非持久对象界面中更新xpo的状态查询
    Java字符串操作方法集
    Java易忘知识点统计
    Android常用依赖库搜集
    Android Studio报错Unable to resolve dependency for ':app@release/compileClasspath':无法引用任何外部依赖的解决办法
    Codewars练习Python
    Python学习日记之正则表达式re模块
    Linux学习日记之crontab使用notify-send实现每小时通知提醒
    Linux学习日记之Deepin下查看crontab运行日志
  • 原文地址:https://www.cnblogs.com/yoyo-sincerely/p/6322880.html
Copyright © 2011-2022 走看看