Sicily 1299 Academy Awards (map + vector容器)
来源:互联网 发布:孕妇奶粉 知乎 编辑:程序博客网 时间:2024/05/17 02:46
链接:http://soj.me/show_problem.php?pid=1299&cid=
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.
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.
For each list, you are supposed to figure out the winner of Best Picture in a single line.
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
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容器)
- sicily--1299. Academy Awards
- Sicily 1299. Academy Awards
- 1004. Academy Awards
- C++容器 vector list map
- vector set map 容器比较
- 文本查询程序(c++)set,vector,map容器实现
- cocos2dx的模板容器简单使用(Vector,Map,Value)
- map容器和vector的结合使用(UVA 11991)
- vector、map容器删除操作总结
- STL常见容器set 、vector、 map 对比
- vector和map 容器的区别
- vector、map容器删除操作总结
- cocos2dx-3.0(13)------容器Vector和Map
- (STL容器) vector. list. set. deque. map.
- vector和map 容器的区别
- list、vector、map容器erase的区别
- 顺序容器vector 与 关联容器map的总结
- 跳河的兔子
- 企业架构介绍
- <转>TCP/IP、Http、Socket的区别
- cocos2d之Box2D详解 鼠标关节实现
- android 按住和松开的事件
- Sicily 1299 Academy Awards (map + vector容器)
- Java内存分配、管理小结
- Android自由选择TextView的文字
- GDB调试总结__1
- Oracle中创建dblink的方法
- OCP-1Z0-051 第91题 TO_DATE转换函数
- springSecurity登录验证分析——AbstractUserDetailsAuthenticationProvider
- Adapter的继承结构
- ZeroMQ之消息丢失解决方法