HDU 1789

Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13357    Accepted Submission(s): 7783


Problem Description
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test. And now we assume that doing everyone homework always takes one day. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.
 

Input
The input contains several test cases. The first line of the input is a single integer T that is the number of test cases. T test cases follow.
Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
 

Output
For each test case, you should output the smallest total reduced score, one line per test case.
 

Sample Input
  
  
3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4
 

Sample Output
  
  
0 3 5

 


说一下题目的思路(做法):

肯定是先做分数高的,所以对分数进行由小到大的排序,完成分数最高的之后找分数第二高的,往分数最高的前面排,再是第三高的,,在往前排若该天有未完成的任务,则放弃该天的任务,算作扣的分数里,再以此类推。


解释一下最后一组测试数据:

排好序后就是 7 6  5  4  3  2    1,对应的天数为:4   2    4    1    4   6;

是这么排的: 1   2  3   4   5       6

                                      7(第四天完成)

1   2     3    4    5    6

             6   7     6(第三天完成)

1    2     3     4    5    6

       5    6      7(5第二天完成)

1     2     3    4    5     6

4    5     6    7(4第一天完成)

1    2   3   4   5   6

4     5   6   7         6(其中再是3,2,但是3,2应该完成的时间被占了,所以不能完成,最后剩下了1,最后一天完成)


已经AC过的代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct M
{
    int date,score;
} A[1005];//定义一个结构体,把天数和分数放在一起
int bigger(const M &a,const M &b)
{
    return a.score>b.score;
}使用结构体排序
int main()
{
    int t,n;
    int in[1005];
    scanf("%d",&t);
    while(t--)
    {
        int ans=0;
        memset(in,0,sizeof(in));
        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);
        sort(A,A+n,bigger);//分数进行由大到小排序
        for(int i=0; i<n; i++)//先从最大的开始,逐渐递减
        {
            int j;
            for(j=A[i].date; j>=1; j--)//最大的在该天完成,接着天数递减
            {
                if(!in[j])//如果该天没有被其他的任务,则为真。若该天有任务,但是时间已经被其他的科目占据,则为假,若没有,则为真。
                {
                    in[j]=true;
                    break;//如果没有被占据,则跳出循环
                }
            }
            if(!j)
                ans+=A[i].score;//如果该天完成了其他作业,而应该在这天写的作业未完成,则加上去
        }
        cout<<ans<<'\n';
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值