Skip the Class
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1182 Accepted Submission(s): 682
Total Submission(s): 1182 Accepted Submission(s): 682
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
2 5 english 1 english 2 english 3 math 10 cook 100 2 a 1 a 2
Sample Output
115 3
///可以用两个map模拟
///AC代码
#include <iostream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <functional>
#define PI acos(-1)
#define eps 1e-8
#define inf 0x3f3f3f3f
#define debug(x) cout<<"---"<<x<<"---"<<endl
typedef long long ll;
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
map<string, int> p1, p2;
map<string, int>:: iterator iter;
string s;
int val;
for (int i = 0; i < n; i++)
{
cin >> s >> val;
if (p1[s] < val)
{
p2[s] = p1[s];
p1[s] = val;
}
else if (p2[s] < val)
{
p2[s] = val;
}
}
int sum = 0;
for (iter = p1.begin(); iter != p1.end(); iter++)
{
sum += iter->second;
}
for (iter = p2.begin(); iter != p2.end(); iter++)
{
sum += iter->second;
}
cout << sum << endl;
}
return 0;
}
///也可以用结构体+map处理
///AC代码
#include <iostream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <functional>
#define PI acos(-1)
#define eps 1e-8
#define inf 0x3f3f3f3f
#define debug(x) cout<<"---"<<x<<"---"<<endl
typedef long long ll;
using namespace std;
struct ff
{
string s;
int val;
} p[210];
bool cmp(ff a, ff b)
{
if (a.s == b.s)
{
return a.val > b.val;
}
else
{
return a.s > b.s;
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> p[i].s >> p[i].val;
}
sort(p, p + n, cmp);
map<string, int> countt;
int sum = 0;
for (int i = 0; i < n; i++)
{
countt[p[i].s]++;
if (countt[p[i].s] <= 2)
{
sum += p[i].val;
}
}
cout << sum << endl;
}
return 0;
}