链接:http://soj.me/show_problem.php?pid=1299&cid=

Description

Selected from 3,850 teams from 1,329 universities in 68 countries competing at 106 sites and preliminary contests worldwide, sixty-eight teams competed for bragging rights and prizes
at The 27th Annual ACM International Collegiate Programming Contest World Finals sponsored by IBM on March 25, 2003, in Hollywood, California. The 2003 World Champion is Warsaw University . And Zhongshan University won the 8th place. During those
days, another world famous event was held in the same place. It was the 75th Annual Academy Awards. It’s also known as Oscar.

We always say that the Best Picture is the most important award of all the awards. Before the Oscar Night, we can’t tell which
film will win Best Picture. Fortunately, we can dope it out from the Nominee List of all the awards other than the Best Picture. I suggest that you should follow my 3 rules here.

l         All the films in the list have chances to win the Best Picture

l         The film which will win the Best Picture is the film which has been nominated the most times in the list

l         If there are more than one film which have been nominated the most times in the list, we will choose the first one which appears in the list

Let’s see such a List below.

VISUAL EFFECTS

THE LORD OF THE RINGS: THE TWO TOWERS

SPIDER-MAN

STAR WARS EPISODE II ATTACK OF THE CLONES

 SOUND EDITING 

THE LORD OF THE RINGS: THE TWO TOWERS

MINORITY REPORT

ROAD TO PERDITION

From the list, we can find that THE LORD OF THE RINGS: THE TWO TOWERS has been nominated twice. And each of the other
films has been nominated only once. So we can say THE LORD OF THE RINGS: THE TWO TOWERS will win the Best Picture.

Your task is to write a program to figure out the anticipatory winner from the list.

Input

The input file will consist of several lists. The first line of each list contains only one integer n (1≤n≤100), representing the number of awards in the list. Then you get n blocks.
Each block indicated the nominees of a distinct award. The first line of each block is the name of the award which is not longer than 80. The second line is mi (1≤mi≤10, 1≤i≤n) - the number of nominated films. In the following lines are
mi film names, one per line. For make the question simple, you can assume that there isn’t any space in the film names.

The input is terminated by a line with one zero.

Output

For each list, you are supposed to figure out the winner of Best Picture in a single line.

Sample Input
 Copy sample input to clipboard
2VISUAL_EFFECTS3THE_LORD_OF_THE_RINGS:_THE_TWO_TOWERSSPIDER-MANSTAR_WARS_EPISODE_II_ATTACK_OF_THE_CLONESSOUND_EDITING3THE_LORD_OF_THE_RINGS:_THE_TWO_TOWERSMINORITY_REPORTROAD_TO_PERDITION0
Sample Output
THE_LORD_OF_THE_RINGS:_THE_TWO_TOWERS

分析: 统计出现频率最高的电影名字。看一下数据范围都不大,时间复杂度为O(n*m), 统计频率用map容器就能够搞定,可是另一个重要的问题就是,题目中要求电影的顺序,所以没办法啦,加一个vector 就OK啦。

。。

代码例如以下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <string>
#include <iterator>
#define RST(N)memset(N, 0, sizeof(N))
using namespace std; vector <string> v;
map <string, int> mp;
map <string, int>:: iterator it;
string award, file, flag; //奖项名字,电影名字,出现频率最高的电影名字;
int n, m; //奖项数,获得每一个奖项的电影名字总数; int main()
{
while(cin >> n && n) {
mp.clear(), v.clear(); //初始化容器。
while(n--) {
cin >> award;
cin >> m;
for(int i=0; i<m; i++) {
cin >> file;
v.push_back(file);
it = mp.find(file); //找到该电影出如今map容器中的位置;
if(it != mp.end()) mp[file]++; //找到,频率加1;
else mp[file] = 1; //未找到,频率为1;并加到map容器其中;
}
}
int max = 0;
for(int i=0; i<v.size(); i++) { //找出出现频率最高的电影名字;
it = mp.find(v[i]);
if(it->second > max) {
max = it->second;
flag = it->first;
}
}
cout << flag << endl;
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

Sicily 1299 Academy Awards (map + vector)集装箱的更多相关文章

  1. UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  2. uva--11991 - Easy Problem from Rujia Liu?(sort+二分 map+vector vector)

    11991 - Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for e ...

  3. map,vector 等容器内容的循环删除问题(C++)

    map,vector 等容器内容的循环删除问题(C++) map,vector等容器的循环删除不能用普通的方法删除: for(auto p=list.begin();p!=list.end();p++ ...

  4. 2018.09.26 洛谷P2464 [SDOI2008]郁闷的小J(map+vector)

    传送门 本来出题人出出来想考数据结构的. 但是我们拥有map+vector/set这样优秀的STL,因此直接用map离散化,vector存下标在里面二分找答案就行了. 代码: #include< ...

  5. 几种常见 容器 比较和分析 hashmap, map, vector, list ...hash table

    list支持快速的插入和删除,但是查找费时; vector支持快速的查找,但是插入费时. map查找的时间复杂度是对数的,这几乎是最快的,hash也是对数的.  如果我自己写,我也会用二叉检索树,它在 ...

  6. Set,List,Map,Vector,ArrayList的区别(转)

    JAVA的容器---List,Map,Set Collection ├List │├LinkedList │├ArrayList │└Vector │ └Stack └Set Map ├Hashtab ...

  7. ACM: NBUT 1646 Internet of Lights and Switches - 二进制+map+vector

    NBUT 1646 Internet of Lights and Switches Time Limit:5000MS     Memory Limit:65535KB     64bit IO Fo ...

  8. c++如何遍历删除map/vector里面的元素

    新技能Get! 问题 对于c++里面的容器, 我们可以使用iterator进行方便的遍历. 但是当我们通过iterator对vector/map等进行修改时, 我们就要小心了, 因为操作往往会导致it ...

  9. list map vector set 常用函数列表

    #include <stdio.h> #include <iostream>//cin,cout #include <sstream>//ss transfer. ...

随机推荐

  1. 将php分页类YII绑定框架,就需要改变风格的基础

    分页类http://blog.csdn.net/buyingfei8888/article/details/40260127 在内部组件分页类 文件名和一致 组件是在什么地方被载入进来的?在主配置文件 ...

  2. 全文检索引擎Solr 指南

    全文检索引擎Solr系列:第一篇:http://t.cn/RP004gl.第二篇:http://t.cn/RPHDjk7 .第三篇:http://t.cn/RPuJt3T

  3. Linux在简短而经常使用的命令

    Linux组成: 内核:的心脏.是执行程序和管理像磁盘和打印机等硬件设备的核心程序. shell:是系统的用户界面,提供了用户和内核进行交互操作的一种接口.它接收用户输入的命令并把它送入内核去执行.是 ...

  4. WEB安全实战(一)SQL盲注

    前言 好长时间没有写过东西了,不是不想写,仅仅只是是一直静不下心来写点东西.当然,拖了这么长的时间,也总该写点什么的.近期刚刚上手安全方面的东西,作为一个菜鸟,也本着学习的目的,就谈谈近期接触到的安全 ...

  5. ASP.NET 运行

    ASP.NET 运行 对于ASP.NET开发,排在前五的话题离不开请求生命周期.像什么Cache.身份认证.Role管理.Routing映射,微软到底在请求过程中干了哪些隐秘的事,现在是时候揭晓了.抛 ...

  6. sails 相关文章

    Node 框架之sails   http://cnodejs.org/topic/555c3c82e684c4c8088a0ca1

  7. dom4j解析xml中指定元素下内容

    需求:XML为例如以下样式,如今我仅仅想取得timer以下的5000和60000. 解决的方法例如以下: <?xml version="1.0" encoding=" ...

  8. css3 shadow为了实现各种漂亮的阴影效果

    <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/h ...

  9. Eamcs ditaa基于字符图形产生的图像上

    ditta和artist mode这是一个好兄弟.artist mode帮我创建一个字符模式速度,ditta是java计划,字符图形可被读取,并生成图像. ditta网站:http://ditaa.s ...

  10. winform正在使用dsoframer迅速&quot;Unable to display the inactive document.Click here to reacitive the document.&quot;

    于winform正在使用dsoframer 1.3加载word档,但在axFramerControl1.Open("NPOI.docx");于axFramerControl1控制显 ...