Hdu - 1789 - Doing Homework again
上题目
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4429 Accepted Submission(s): 2595
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.
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
题意就是有很多作业,每一个作业有一个最后上交的期限以及它的价值。求最后他有多少的价值没有得到。
这一题是贪心,贪心的策略是先做价值最大的作业,在最后的期限那天做。
题目说他最多只有1000份作业,但是上交期限没有说不大于1000,因此这里的做法是读入数据的时候如果上交的时间大于1000,那就把它改成1000。然后按作业的价值从大到小排序,如果价值相同,就按日前大到小排序。然后从数组的开头开始判断每一份作业,从它的期限之日开始向前扫描,如果遇到了还没有放的日子,就把作业放到这一天上,并标记好这一天已经有安排了。
为什么这种策略可以行得通,我也不太懂为什么,因为不知道怎样证明,但是如果问我为什么要用这种做法的话,就是因为先把价值大,期限久的作业先安排好,然后下一个安排的必定是作业价值第二大的了,那当然是放在其期限的结束那一天,如果遇到两个价值期限都一样的的作业,那先做拿个都一样。
大概是还没有完全搞懂贪心的思想,总觉得贪心这个名词用得不对。看来还要努力啊。