Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1789
/*Doing Homework againtime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) total submission (s) : 7903 Accepted Submission (s): 4680Problem Descriptionignatius have just come back school from the 30th ACM/ICPC. Now he had 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 would reduce his score of the final Test. And now we assume this doing everyone homework always takes one day. So Ignatius wants-to-help him to arrange the order of doing homework to minimize the reduced score. Inputthe input contains several test cases. The first line of the input was a single integer T so 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 this indicate the deadlines of the subjects, and the next line contains NIntegers that indicate the reduced scores. Outputfor Each test case, you should the output of the smallest total reduced score, one line per test case. Sample Input333 3 310 5 131 3 2 371 4 6 4 2 4 2 1 7 6 5 4 Sample Output035 authorlcy Source2007 Provincial Training Team Practice Tournament (10) _ Thanks to Doom Iii*///Greedy Algorithm#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intMAXN = ++ -;structnode{intd, S;}; Node NODE[MAXN];intMARK[MAXN];BOOLCMP (Node A, Node B) {returnA.S >B.S;}intMain () {intT, N; while(~SCANF ("%d", &t)) { while(t--) {scanf ("%d", &N); memset (Mark,0,sizeof(Mark)); for(inti =1; I <= N; i++) scanf ("%d", &NODE[I].D); for(inti =1; I <= N; i++) scanf ("%d", &node[i].s); Sort (Node+1, node+n+1, CMP); intI, j, cnt =0; for(i =1; I <= N; i++){ for(j = node[i].d; J >=1; j--){ if(!Mark[j]) {Mark[j]=1; Break; } } if(J = =0) CNT + =Node[i].s; } printf ("%d\n", CNT); } } return 0;}
HDU 1789 Doing Homework Again (greedy algorithm)