HDU 1789 贪心水题

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);


    }


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值