HDU 1789
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1789
题目分析:
这是为广大学生服务的题目,关于做那科作业会使毕业评定最好。
这也是一个贪心水题。根据分数排序。
代码:
#include <cstdio>
#include <algorithm>
#include <cstring>
struct node
{
int date;
int score;
} a[1009];
int hash[1009];
bool cmp(struct node a, struct node b)
{
if(a.score != b.score) return a.score > b.score;
else if(a.date != b.date) return a.date < b.date;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d", &a[i].date);
for(int i = 0; i < n; i++)
scanf("%d", &a[i].score);
std::sort(a, a + n, cmp);
memset(hash, 0, sizeof(hash));
int res = 0;
int j = 0;
for(int i = 0; i < n; i++)
{
for(j = a[i].date; j > 0; j--)
{
if(hash[j] == 0)
{
hash[j] = 1;
break;
}
}
if(j <= 0) res += a[i].score;
}
printf("%d\n", res);
}
}