UVa 11729-commando War

Source: Internet
Author: User

"Title translation":

Problem analysis: Because tasks can be executed in parallel, it is intuitively a task that takes a long time to prioritize deployment. But this to the topic also gives you the task of time, so easy to let people think more.

There are only two possible cases for tasks x and Y, regardless of the time it takes to account for the task. X ends before y, and x ends after Y. Here it is discussed that X is done before Y.

When x and Y positions are not swapped, the completion time is: B[x] + b[y] + j[y]

After swapping H and Y positions, the completion time is: B[y] + b[x] + j[x]

If J[y] is greater than j[x], then the time is shortened after the interchange, so y should be executed before X. The other situation is similar.

This proves that the greedy strategy can be boldly used in the future.

#include <Cstdio>
#include <cstring>
#include <algorithm>
using namespace Std;
struct people
{
int b,j;
} p[1005];
int CMP (People a,people B)
{
Return a.j>b.j;
}
int main ()
{
int n,cas=0;
while (scanf ("%d", &n)!=eof&&n)
{
cas++;
for (int i=0; i<n; i++)
scanf ("%d%d", &P[I].B,&P[I].J);
Sort (p,p+n,cmp);
int sum=0,ans=0;
for (int i=0; i<n; i++)
{
sum+=p[i].b;
Ans=max (ANS,SUM+P[I].J);
}
printf ("Case%d:%d\n", Cas,ans);
}
return 0;

}

UVa 11729-commando War

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.