hdu-6015map容器的应用
来源:互联网 发布:做藏头诗的软件 编辑:程序博客网 时间:2024/06/05 18:22
Skip the Class
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 642 Accepted Submission(s): 370
Problem Description
Finally term begins. luras loves school so much as she could skip the class happily again.(wtf?)
Luras will take n lessons in sequence(in another word, to have a chance to skip xDDDD).
For every lesson, it has its own type and value to skip.
But the only thing to note here is that luras can't skip the same type lesson more than twice.
Which means if she have escaped the class type twice, she has to take all other lessons of this type.
Now please answer the highest value luras can earn if she choose in the best way.
Luras will take n lessons in sequence(in another word, to have a chance to skip xDDDD).
For every lesson, it has its own type and value to skip.
But the only thing to note here is that luras can't skip the same type lesson more than twice.
Which means if she have escaped the class type twice, she has to take all other lessons of this type.
Now please answer the highest value luras can earn if she choose in the best way.
Input
The first line is an integer T which indicates the case number.
And as for each case, the first line is an integer n which indicates the number of lessons luras will take in sequence.
Then there are n lines, for each line, there is a string consists of letters from 'a' to 'z' which is within the length of 10,
and there is also an integer which is the value of this lesson.
The string indicates the lesson type and the same string stands for the same lesson type.
It is guaranteed that——
T is about 1000
For 100% cases, 1 <= n <= 100,1 <= |s| <= 10, 1 <= v <= 1000
And as for each case, the first line is an integer n which indicates the number of lessons luras will take in sequence.
Then there are n lines, for each line, there is a string consists of letters from 'a' to 'z' which is within the length of 10,
and there is also an integer which is the value of this lesson.
The string indicates the lesson type and the same string stands for the same lesson type.
It is guaranteed that——
T is about 1000
For 100% cases, 1 <= n <= 100,1 <= |s| <= 10, 1 <= v <= 1000
Output
As for each case, you need to output a single line.
there should be 1 integer in the line which represents the highest value luras can earn if she choose in the best way.
there should be 1 integer in the line which represents the highest value luras can earn if she choose in the best way.
Sample Input
25english 1english 2english 3math 10cook 1002a 1a 2
Sample Output
1153#include <bits/stdc++.h>using namespace std;const int N=105;int T,n,sum;struct node{string name;int value;}stu[N];bool cmp(const node& x,const node& y){return x.value>y.value;}int main(){cin>>T;while(T--){cin>>n;for(int i=1;i<=n;i++)cin>>stu[i].name>>stu[i].value;sort(stu+1,stu+1+n,cmp);sum=0;//使用map容器,用的[],有点类似数组 map<string,int> mp;//注意这里的mp的value默认全部为0for(int i=1;i<=n;i++){if(mp[stu[i].name]==2)//mp[stu[i].name]直接插入了这个key continue;//使用2次了,后面相同的都不需要了else{mp[stu[i].name]++;sum+=stu[i].value;} }cout<<sum<<endl;}return 0;}
0 0
- hdu-6015map容器的应用
- map容器的应用:hdu 1004 Let the Balloon Rise
- C++ map容器的应用
- zju-1159-map容器的应用
- 容器map的应用:CodeForces - 501B
- HDU 2648 map的应用
- Map容器与multimap容器应用的小知识
- map容器简单应用
- map容器应用
- HDU 1263 水果 map容器
- hdu 1217 floyd+map容器
- hdu 2112 floyd+map容器
- hdu 2923 floyd+map容器
- HDU4585Shaolin Map容器简单应用
- hdu 1075 map函数的应用
- HDU 4287 Intelligent IME map的应用
- hdu-1075 map映射表的应用。
- HDU 2072 单词数 map的应用
- (OK) 移植,编译,安装 LineageOS-14.1-kiwi (Android-7.1.1,运行在Huawei honor 5x) for VirtualBox
- 网络摄像机IPCamera RTSP直播播放网络/权限/音视频数据/花屏问题检测与分析助手EasyRTSPClient
- Meterial Design最佳体验(1): 使用Toolbar, CoordinatorLayout, AppBarLayout等实现精美标题栏
- tp框架中const的设置问题
- 258. Add Digits
- hdu-6015map容器的应用
- getting started with zookeeper and first zookeeper session
- UVA 1616 Caravan Robbers(二分 + 小数变分数)
- 文章标题
- 队列
- 《算法精讲:C语言描述》-单链表实现代码
- 【Unity优化】构建一个拒绝GC的List
- poj1324
- coursera ML笔记 ----week2 多变量的线性回归