Skip to main content
  1. Posts/

poj 2643 election

·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

题目链接:http://poj.org/problem?id=2643

在考stl的map…

我是定义了一个string 指向string的,表示参选人和党派的关系,和一个string 指向int的,表示某个党派被投票的次数。

需要注意的是!!!

需要注意的是!!!

需要注意的是!!!

字符串读入部分…

在输入n和m之后,会有一个回车符没读进去…(大概是这样?)

如果不处理一下的话,后面的字符串就会少读入一个…(sad)

解决的办法是在读完n和m之后写一个getchar(); 把回车符读掉。

 1
 2
 3    /* ***********************************************
 4    Author :111qqz
 5    Created Time :2016年02月19日 星期五 15时44分55秒
 6    File Name :2643.cpp
 7    ************************************************ */
 8
 9    #include <algorithm>
10    #include <cstdio>
11    #include <iostream>
12    #include <cstring>
13    #include <string>
14    #include <cmath>
15    #include <map>
16    #include <stack>
17    #include <queue>
18
19    using namespace std;
20    typedef long long LL;
21    const int inf = 8E8;
22    int n,m;
23    string ans;
24    map<string,string>m1;
25    map<string,int>m2;
26    string c_name,p_name;
27    char ch;
28    int main()
29    {
30        cin>>n;
31        getchar();
32        for ( int i = 1 ; i <= n ; ++i )
33        {
34            getline(cin,c_name);
35
36            getline(cin,p_name);
37            m1[c_name]=p_name;
38        }
39        cin>>m;
40        getchar();
41        for ( int i = 1 ; i <= m ; i++ )
42        {
43            getline(cin,c_name);
44            m2[c_name]++;
45        }
46        map<string,int>::iterator it;
47        int mmax=-1;
48        for (it=m2.begin();it!=m2.end();it++)
49        {
50            if (it->second>mmax)
51            {
52               mmax=it->second;
53               ans = m1[it->first];
54            }
55        }
56        int p = 0;
57        for ( it = m2.begin();it!=m2.end();it++)
58        {
59            if (it->second==mmax)
60            {
61                p++;
62            }
63        }
64        if (p!=1)
65        {
66            ans="tie";
67        }
68
69        cout<<ans<<endl;
70
71
72
73    	return 0;
74    }

Related

poj 1833 排列

·1 min
http://poj.org/problem?id=1833 还是next_permutation. 这次是Int类型的 需要注意的是next_permutation是先判断时候有后继,返回一个bool值,如果为true,就转化到后继。

poj 1256 Anagram

·1 min
http://poj.org/problem?id=1256 题意是说求出一个字符串的全排列,按字典序 需要注意的是字典序和传统意义上的字典序不同

codeforces 548B Mike and Fun

·1 min
http://codeforces.com/problemset/problem/548/B 比赛的时候不懂为什么就没做出来…. 其实很容易想到一个o(q*(n+m))的做法… 就是每次更新,要同时更新当前更新行的最大连续和….O(m)可以完成…然后在O(n)扫一遍,找到所有行中的最大值。 然后需要注意的是,在第一次更改之前就要把每个行的最大值处理出来l.. 然后cf机器真是够快,O(nmq)的1.2S过。。。。