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
  • 相关阅读:
    【WEB前端开发最佳实践系列】高可读的HTML
    【Web前端开发最佳实践系列】标准的HTML代码
    Web服务器配置Gzip压缩提升网站性能
    【Web前端开发最佳实践系列】前端代码推荐和建议
    【前端系列】移动前端开发之viewport的深入理解
    【Spring Boot && Spring Cloud系列】那些Spring Boot中踩过的坑
    【Spring Boot && Spring Cloud系列】Spring Boot的启动器Starter
    【Spring Boot&&Spring Cloud系列】提高数据库访问性能
    【Spring Boot&& Spring Cloud系列】单点登录SSO之OAuth2官方开发文档翻译
    【Spring Boot&& Spring Cloud系列】单点登录SSO概述
  • 原文地址:https://www.cnblogs.com/yoyo-sincerely/p/6322880.html
Copyright © 2011-2022 走看看