HDOJ 1789-Doing Homework again【贪心】

来源:互联网 发布:美国移交域名管理 编辑:程序博客网 时间:2024/06/05 11:44

Doing Homework again

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


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
 解题思路:
我们输入这一科的截止日期和学分,我们需要找到挂了多少分,每科只需要1天完成。
/*  -----------------  *//*         |           *//*         |           */    /*         |           *//*  -----------------  *//*         |           */ /*         |   \       *//*         |    \      *//*  -----------------  */#include<stdio.h>#include<string.h>//string strcpy strcmp#include<math.h>#include<algorithm>#include<queue>#define nz 101000using namespace std;struct node{int qx;int fs;}q[nz];int cmp(node a,node b){if(a.fs==b.fs){return a.qx<b.qx;}else{return a.fs>b.fs;}}int main(){int a;int ss[10000];scanf("%d",&a);while(a--){int n,y,j;scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&q[i].qx);}for(int j=0;j<n;j++){scanf("%d",&q[j].fs);}sort(q,q+n,cmp);//特别注意这里要求按照学分的由大到小排int sum=0;memset(ss,0,sizeof(ss));for(j=0;j<n;j++)if(!ss[q[j].qx]){ss[q[j].qx]=1;//找到日期对应的数组位置占下这个点continue;}else//如果有日期重复的课{for(y=q[j].qx-1;y>=1;--y)//往前找找到没有被占的那一天占下那一天 如果日期都被占完则说明该科要挂 在sum中加上学分if(!ss[y]){ss[y]=1;break;}if(y==0)sum+=q[j].fs;}printf("%d\n",sum);}return 0;}


1 0
原创粉丝点击