Doing Homework Again

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1789

Typical greed, but also in this topic mastered the most typical of greed symbol, that is, the use of sorting algorithm ... A little low, though.


Problem Description: Ignatius after the game back, each teacher gave Ignatius a deadline to hand in the homework, if not pay off points. Each job must be completed in one day, the minimum number of points to deduct. First enter a T to indicate that there is a T group of test data, then each group of data first entered an n, representing n jobs, and then enter two lines, the first line represents the date of each job to be delivered, the second line indicates the corresponding if not to pay the job to buckle points. Outputs the minimum score to buckle.

Problem Solving Ideas:

According to the end time from small to large sort, for each end time traversal, in the traversal if the current end time is smaller than the current record number of days, indicating that the current is long overdue, but to the current day has not been completed, this is the need to record and add the number of days, but now also need to do not complete the traversal, To find the smallest score of previous punishments.

#include <iostream> #include <string> #include <cstdio> #include <cstring> #include <
Algorithm> using namespace std;
	struct t{int time,score;
BOOL visit;
}A[1010];
	BOOL CMP (T a,t b) {if (a.time!=b.time) return a.time<b.time;	
Return a.score>b.score;
	} int main () {int case;
	scanf ("%d", &case);
	 while (case--) {int n,sum=0;
	 scanf ("%d", &n);
	 for (int i=0;i<n;i++) {scanf ("%d", &a[i].time);
     a[i].visit=0;
	 } for (int i=0;i<n;i++) scanf ("%d", &a[i].score);
	 
	Sort (a,a+n,cmp); 
	int count=0;
	  for (int i=0;i<n;i++) {count++; a[i].visit=1;//Mark completed if (a[i].time<count) {//If the current deadline has timed out count--;//must be today or before the penalty smaller mark for unfinished, that is, this day nothing is dry I
	   NT X=i;
	   for (int j=0;j<i;j++) {if (A[j].score<a[x].score && a[j].visit==1) x=j; 
	  } Sum=sum+a[x].score;  a[x].visit=0; 
	Find the least loss of the task, let him mark unfinished, note here if I corresponding to the minimum penalty in this modification is not completed, if there is a smaller//let the smallest modification to unfinished, the current is still complete} } printf ("%d\n", sum);
} return 0;
 }

As a greedy classic, this problem is very good ...


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.