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
  • 相关阅读:
    Linux04:压缩与解压
    Linux03:基本权限与初始权限
    Linux02:基本命令、查看文件、链接命令
    Linux01:虚拟机配置与系统安装
    分库分表和数据库分片方案
    mysql的锁
    redo log和undo log、事务
    Android : 代码多维度管理(产品风味)
    Android : 网络adb配置及有线端口占用解决方法
    Linux学习: 触摸屏驱动
  • 原文地址:https://www.cnblogs.com/yoyo-sincerely/p/6322880.html
Copyright © 2011-2022 走看看