HDU1789Doing Homework again

来源:互联网 发布:易语言2017盗号源码 编辑:程序博客网 时间:2024/06/01 17:21


Doing Homework again

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


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
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
 

Sample Output
035
 

Author
lcy
 

Source
2007省赛集训队练习赛(10)_以此感谢DOOMIII

#include<iostream>#include<algorithm>#include<cstring>using namespace std;struct stu{int end,fen;}arr[1010];bool cmp(stu x,stu y){if(x.fen==y.fen)return x.end<y.end;return x.fen>y.fen;}int main(){    int T,a[1010];cin>>T;while(T--){int N,ans=0,j;cin>>N;memset(a,0,sizeof(a));for(int i=0;i<N;i++)cin>>arr[i].end;for(int i=0;i<N;i++)cin>>arr[i].fen;sort(arr,arr+N,cmp);for(int i=0;i<N;i++){for(int j=arr[i].end;j>=1;j--){if(a[j]==0){a[j]=1;break;}if(j==1)ans+=arr[i].fen;}}cout<<ans<<endl;} }


参考别人的博客题解

先按照扣分从大到小排序,分数相同则按照截止日期从小到大排序。。
 
然后按顺序,从截止日期开始往前找没有占用掉的时间。
如果找不到了,则加到罚分里面

单独设置一个数组保存这一天是否完成作业。。。。如果没有安排,就在这一天做。