uva11729
The test instructions of this question is
You have n subordinates, each of whom needs to complete a task. I need you to spend BI minutes on the task, and then he will immediately independently, without interruption to perform JI minutes after the task.
You need to choose the order of the tasks, so that all tasks are executed as early as possible (that is, the last completed task should be completed as soon as possible). Note that it is not possible to give a task to two subordinates at the same time
But the men can perform their respective tasks at the same time.
Minimum time to complete all tasks
In fact, we know that this is a sort of problem. Of course sometimes it can be turned into other problems.
Let's start by making it a sort of problem.
Then each element has two properties confessed time a, the completion of the task of time B, obviously this is a two-dimensional partial order problem (?)
Then we consider that there are three cases in the first dimension (equal to, greater than, less than), and there are three cases in the second dimension.
By the multiplication principle of combinatorial mathematics. The total number of final results is 3*3=9
Then we enumerate the small data to see how the adjacent two elements are placed to minimize the results, and if this is OK then we can bubble sort
By exchanging to maintain this nature, of course, this is to have the premise, that is to meet the properties of the optimal substructure, that is, the problem
To be satisfied if any of the adjacent elements in my sequence satisfies the order in which the results are minimized, my overall results are minimal.
Should be satisfied with the properties of the optimal substructure, then we analyze the problem. Well, obviously, you're taking it 22 neighbors.
Start with an element and slowly add up. We adjust the order of each element by adding it. So we'll make sure we get Max (pre-element,cur-element) every time.
Every time we make this the cur-element to be considered is the smallest, then we finally get the maximum value will be the smallest.
So if we use the exploratory method to draw the picture, we can analyze the law in nine cases.
We have drawn 5 kinds of. But it's enough to see. We'll do the task first, and the time will be shorter.
So we actually found out in whatever order. The sum of time to schedule a task is fixed. But the results are different.
The difference is in assigning a task prefix and adding which execution task time contributes to the answer. Then obviously we can get. The longest time to perform a task should be
A shorter allocation task prefix and: This will reduce the contribution of this maximum to the answer.
There are some places that are not very well understood. Let's do a few more similar questions.
UVA's 64-bit integer is%LLD also pay attention to the answer output format: Do not think the value of the pair can be AC.
Attach the AC code
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespaceStd;typedefLong Longll;Const intmaxn=1e3+7;intN;structnode{intb;} NODE[MAXN];BOOLCMP (node A,node b) {if(a.b!=b.b)returnA.b>b.b; Else returnA.a>B.A;}intMain () {intCnt=0; while(~SCANF ("%d",&N)) { if(n==0) Break; inti,j; for(i=0; i<n;++i) {scanf ("%d%d",&node[i].a,&node[i].b); } sort (Node,node+n,cmp); ll Previd1=node[0].a; ll MX=previd1+node[0].b; for(i=1; i<n;++i) {PREVID1+=node[i].a; MX=max (mx,previd1+node[i].b); } printf ("Case %d:%lld\n",++cnt,mx); } return 0; }
Classic Greedy Algorithm uva11729