6015 Skip the Class(BestCoder Round #92)

来源:互联网 发布:阿里云磁盘扩容 编辑:程序博客网 时间:2024/05/16 07:49

Skip the Class

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
2
5
english 1
english 2
english 3
math 10
cook 100
2
a 1
a 2

Sample Output
115
3

我也不知道这道题当时怎么想的?当时写的WA了19发,然后这几天补题的时候看到重写一遍1A了,哎…..可能真的刷水题有用吧(在题感上)

#include<bits/stdc++.h>using namespace std;struct node {    string a;    int b;}E[105];map<string,int>ans;bool cmp(node x,node y) {return x.b>y.b;}int main(){    ios::sync_with_stdio(0);    cin.tie(0);    int t,n;    cin>>t;    while(t--) {        cin>>n;        for(int i=0;i<n;i++) {cin>>E[i].a>>E[i].b;ans[E[i].a]=0;}        sort(E,E+n,cmp);        int sum=0;        for(int i=0;i<n;i++) {            if(ans[E[i].a]<2) {ans[E[i].a]++;sum+=E[i].b;}        }        cout<<sum<<endl;    }    return 0;}

或许另一个原因是自己当时不能熟练使用结构体…..或者说没想到用结构体…..还有数量小的时候,要学会用map做一一对应

原创粉丝点击