HDU-6015-Skip the Class(STL:map)
2018-01-20 01:08
351 查看
Skip the Class
[align=left]Problem Description[/align]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.
[align=left]Input[/align]
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
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
2
5
english 1
english 2
english 3
math 10
cook 100
2
a 1
a 2
[align=left]Sample Output[/align]
115
3
[align=left]Source[/align]
BestCoder Round #92
#include<bits/stdc++.h>
using namespace std;
struct node {
char s[20];
int val;
} ca[105];
bool cmp(node a,node b) {
return a.val>b.val;
}
int main() {
int t,n;
cin>>t;
map<string,int>mp;
while(t--) {
cin>>n;
mp.clear();//清空!!
for(int i=0; i<n; i++) {
cin>>ca[i].s>>ca[i].val;
}
sort(ca,ca+n,cmp);
int sum=0;
for(int i=0; i<n; i++) {
if(mp[ca[i].s]==2)
continue;
else {
mp[ca[i].s]++;
sum+=ca[i].val;
}
}
printf("%d\n",sum);
}
}
STL学习,map应用,贪心算法
题意大概是:逃课最多两次,求逃课的最大价值。
相关文章推荐
- HDU 6015 Skip the Class (map)
- HDU 6015 Skip the Class【BestCoder Round #92】map
- 【STL】hdu 6015 Skip the Class
- HDU 6015 Skip the Class【贪心】【map】
- 【杭电6015】Skip the Class-map-STL
- 【STL】hdu 6015 Skip the Class
- HDU 6015 Skip the Class(map用法)
- [HDU] 6015 - Skip the Class - 贪心 + STL
- HDU:6015 Skip the Class(map)
- 【HDU-oj】-6015-Skip the Class(map string vector)
- HDU 6015 Skip the Class 优先队列 map的使用
- HDU 6015 Skip the Class
- HDU 6015-Skip the Class(模拟-结构体排序)
- hdu 6015 Skip the Class
- HDU-6015 Skip the class
- (bc 1001) hdu 6015 skip the class
- BestCoder Round #92 Skip the Class(STL中map的应用)
- HDU-6015 Skip the Class
- HDU 6015 Skip the Class
- HDU 6015 bestcoder #92 Skip the Class