HDU 1789 Doing Homework Again (greedy algorithm)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.