HDU 1789 Doing Homework again

Source: Internet
Author: User

This problem is a simple greedy problem, the topic is to be deducted at least the score, then we should try to get the most points. First, the data is sorted in the order of the scores from large to small (if the same is deadline from small to large rows),

The maximum score is then assigned to the last day of the deadline, and if the day has been scheduled, it is scheduled for one day until it cannot be scheduled, then the sum is added.

#include"iostream"#include"algorithm"#include"stdio.h"#include"string.h"#include"Cmath"#defineMX 1005using namespacestd;structnode{intdeadline; intscore;} IGNATIUS[MX];intDONE[MX];BOOLcmpConstNode A,ConstNode B) {    if(A.score!=b.score)returnA.score>B.score; Else if(A.deadline!=b.deadline)returna.deadline<B.deadline;}intMain () {intT; CIN>>T;  while(t--)    {        intn,i,j; CIN>>N;  for(i=1; i<=n;i++) cin>>Ignatius[i].deadline;  for(i=1; i<=n;i++) cin>>Ignatius[i].score; memset (Done,0,sizeof(done)); Sort (Ignatius+1, ignatius+n+1, CMP); intsum=0;  for(i=1; i<=n;i++)        {            if(!done[ignatius[i].deadline]) done[ignatius[i].deadline]=1; Else            {                 for(j=ignatius[i].deadline-1; j>=1; j--)                {                    if(!done[j]) {done[j]=1; Break;} }                if(j<=0) sum+=Ignatius[i].score; }} cout<<sum<<Endl; }    return 0;}
View Code

HDU 1789 Doing Homework again

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.