Nyoj 757 Final Exam "Priority queue + greedy"

Source: Internet
Author: User

Time limit for final exams:MS | Memory limit:65535 KB Difficulty:2
Describe
soon the exam, little T has a lot of homework to do, and each teacher gave out the assignment to pay the deadline, if not handed in within the specified period of homework will deduct the final score, assuming that the completion of each homework need a day, you can help small t deduction of the smallest score?
Input
Enter N, which represents N-gate homework (n<2000), next n lines, two numbers per line, A, B, respectively, indicating the deadline for the delivery of the job, and the late deduction of the score.
(End of file)
Output
the minimum fraction of the output deduction.
Sample input
33 103 53 131 63 21 371 34 26 14 72 64 53 4
Sample output
035
Place data in priority queue, prioritize team list team order according to score from large to small, set array vis[] to mark the corresponding date whether there is idle time,
If there is no idle time, the current score must be discarded:
#include <stdio.h> #include <cstring> #include <queue>using namespace std;struct node{int time;int score;friend bool Operator < (node A,node b) {return a.score<b.score;}}; int main () {int N,m,j,i,t;int vis[2100];while (scanf ("%d", &t)!=eof) {memset (vis,0,sizeof (VIS));p Riority_queue <node>q;node x;for (i=0;i<t;i++) {scanf ("%d%d", &n,&m); X.time=n;x.score=m;q.push (x);} int Sum=0;for (i=0;i<t;i++) {x=q.top (); for (j=x.time;j>=1;j--) {if (vis[j]==0) {vis[j]=1;break;}} if (j==0) Sum+=x.score;q.pop ();} printf ("%d\n", sum);} return 0;}

  

Nyoj 757 Final Exam "Priority queue + greedy"

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.