杭电1789_贪心

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789

题目大意:有 t 组数据, 每组数据包含一个n, n个作业的截止日期 和 迟交要扣的分数, 问做完这些作业扣的最少分数是多少?

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <cstdlib>
 6 #include <cmath>
 7 #include <set>
 8 #include <map>
 9 #include <vector>
10 using namespace std;
11 
12 struct node
13 {
14     int f, t;
15 }a[1001];
16 int cmp(node a, node b)//扣分高的肯定先做, 排在前面,然后是截止日期小的排前面
17 {
18     if(a.f != b.f)
19         return a.f > b.f;
20     else
21         return a.t < b.t;
22 }
23 int ans[10010];
24 int main()
25 {    
26     int t, n;
27     scanf("%d", &t);
28     while(t--)
29     {
30         scanf("%d", &n);
31         for(int i = 1; i <= n; i++)
32             scanf("%d", &a[i].t);
33         for(int j = 1; j <= n; j++)
34             scanf("%d", &a[j].f);
35         sort(a + 1, a + n + 1, cmp);   
36         memset(ans, 0, sizeof(ans));  
37         int sum = 0;
38         for(int i = 1; i <= n; i++)
39         {
40             int temp = a[i].t;
41             while(ans[temp])           
42                 temp--;
43             if(temp == 0)
44                 sum += a[i].f;                        
45             else
46                 ans[temp] = 1;
47         }
48         printf("%d\n", sum);
49     }
50     return 0;
51 }

 

posted @ 2016-05-21 22:31  海无泪  阅读(169)  评论(0编辑  收藏  举报