hdu 1789 贪心算法

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
题意:小孩做作业,一天做一样作业。作业有交作业的期限和成绩,超过了期限就不能交了。要你写个程序如何安排日程能丢分最少。
输入:第一行是输入测试次数n,接下来每个测试第一行是输入有几科科目,第二行输入每科的最后期限,第三行输入每个的分数。
思路:贪心策略:作业当然先做分数高的呀。所以先按分数排序,排好后就可以来安排日程啦,需要一个记下日程的一维表date[]。首先要最高分的肯定要做的,那么就需要安排在交作业的日期前都可以,怎么安排才不会和占用其他要先交的分数比较高的日程呢?所以我们就要把它安排交的最后一天来写(在date数组打上标记),这样就不会丢失最优解。如果当前日程已经被安排了,就向前推(因为分数高,必须做嘛)。最后如果都安排到0了还没它的位置,就只有放弃了。关于是否需要在分数相同是否要排日程问题,这是没有必要的,因为就算大的日程递推安排到小的日程那天,相同的成绩做哪一个都没问题的。
View Code

 

posted @ 2018-11-25 21:41  简单的也不会啊  阅读(245)  评论(0编辑  收藏  举报