hdu 6015

题意:n节课,然后给出课程名和翘课价值,每个课程不能逃课超过2次,问得到的最大逃课价值

思路:按照价值排序,然后得到最大价值的2次,哦了。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 struct node
 4 {
 5     string s;
 6     int x;
 7 }a[103];
 8 bool cmp(node p,node q){
 9     return p.x>q.x;
10 }
11 map<string ,int >b;
12 int main()
13 {
14     int t;
15     int n;
16     scanf("%d",&t);
17     while(t--){
18             long long sum=0;
19             b.clear();
20         scanf("%d",&n);
21         for(int i=1;i<=n;i++)
22         {
23             cin>>a[i].s;
24              scanf("%d",&a[i].x);
25         }
26 
27         sort(a+1,a+1+n,cmp);
28         for(int i=1;i<=n;i++){
29             b[a[i].s]++;
30             if(b[a[i].s]>=3)
31                 continue;
32             sum+=a[i].x;
33         }
34         printf("%I64d
",sum);
35     }
36 }
原文地址:https://www.cnblogs.com/hhxj/p/6953547.html