[HDU] 6015

来源:互联网 发布:成都淘宝运营招聘 编辑:程序博客网 时间:2024/06/09 21:43

Skip the Class

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1308    Accepted Submission(s): 747


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.
 

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
 

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.
 

Sample Input
25english 1english 2english 3math 10cook 1002a 1a 2
 

Sample Output
1153
 

Source
BestCoder Round #92
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:  6216 6215 6214 6213 6212 

新的一学期你有很多课要上,每个课如果翘课你能获得一定的价值,课程名字会重复,同名的课你最多翘两门,问你能获得的最大价值。


直接用两个MAP分别维护最大值和次大值就好了。
然后每得出一个新的价值我们和最大值次大值比较一下就好了=。=


然后等号稍微注意一点

#include <bits/stdc++.h>#define LL long longusing namespace std;int main(){    int ncase;    int n;    LL ans;    map<string, int> M1;    map<string, int> M2;    cin >> ncase;    while(ncase --){        cin >> n;        ans = 0;        M1.clear();        M2.clear();        for(int i = 0; i < n; i ++){            string str;            int cnt;            cin >> str >> cnt;            if(cnt > M1[str]){                if(cnt > M2[str]){                    M1[str] = M2[str];                    M2[str] = cnt;                }                else if(cnt <= M2[str]){                    M1[str] = cnt;                }            }        }        for(map<string, int>::iterator it = M1.begin(); it != M1.end(); it ++){            ans += it -> second;        }        for(map<string, int>::iterator it = M2.begin(); it != M2.end(); it ++){            ans += it -> second;        }        cout << ans << endl;    }    return 0;}



原创粉丝点击