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
  • 相关阅读:
    关于标签类的注意事项
    层叠样式表css的优先级
    link常用的作用
    html中属于布尔类型的属性
    行级标签和块级标签的区别
    拥有inline-block属性的标签
    JDK中的Timer和TimerTask详解(zhuan)
    关于 MySQL LEFT JOIN 你可能需要了解的三点(zhuan)
    Logger日志级别说明及设置方法、说明 (zhuan)
    Velocity教程 (zhuan)
  • 原文地址:https://www.cnblogs.com/yoyo-sincerely/p/6322880.html
Copyright © 2011-2022 走看看