ACM Learning process-uvalive 7147 World Cup (category discussion && greed)

Source: Internet
Author: User

Title Link:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ problem&problem=5159

The main idea is that n individuals to play 22 of the game, win a score of a , draw B points, losing C points.

Then take the first m - name finalist, the minimum possible score for the finalists and the maximum possible score of the person who was eliminated.

The first thing you can think of is that wins a minus C and wins C minus a are exactly the same.

So you can consider making A big C Small.

Then start the discussion of the situation:

(1) B min

1· In this case all draw, can make the finalists of the lowest score.

2· Then you need to consider the maximum possible score of the person who is eliminated:

Must divide these people into m+1+n-m-1 .

Because to make this ' 1 ' score as large as possible, naturally consider let n-m-1 personal all negative field elimination.

So the front m+1 Individuals get a * (n-m-1) points first.

Then we need to make this ' 1 ' as big as possible, first he can play with half of the people in the game, and the other half of the people playing the negative field, which is more advantageous than a draw. Then half of the people beat the other half, and that's where all the scores are balanced.

At this time also get m/2* (a+c) points.

Finally, if m is an odd number, then the last one is playing negative field.

Do this, because ' 1 ' can win only half of the M person, otherwise he will not be the last.

So the middle half wins half the negative, and finally m%2 that the game cannot win.

In addition c>b, so consider m%2 that field negative.

(2) B Max

1· In this case all draws, can let the elimination of the person's score maximum.

2· Then need to consider the minimum possible score of the person around;

Must divide these people into m-1+1+n-m .

To make the ' 1 ' score as small as possible, it is natural to consider making the m-1 Individual a winner.

So the front n-m+1 individuals get c* (m-1) points first.

Then we need to make this ' 1 ' as small as possible, first he can play with half of the n-m, and the other half of the people playing the negative field, which is less than the draw score.

At this time also get (n-m)/2* (a+c) points.

Finally, if n-m is odd, then the last game wins.

Do this, because ' 1 ' can only have a negative m person half of the people, otherwise he will certainly not be the first place.

So the middle half wins half of the negative, and finally (n-m)%2 that a game can not be negative.

Also a<b, so consider (n-m)%2 that win.

(3) 2*b < A+c in the remaining cases :

Why consider the relationship between the two, because the above discussion has found a subtle link.

1· The smallest possible fraction of the person considering the circumference;

Inevitable m-1+1+n-m

Then let the front of the m-1 Individual wins the field, then the inevitable ' 1 ' first need to defeat m-1 field.

Then he needs to get over half the people at least (n-m) , and in this case he chose a draw score smaller because of the 2*b < a+cat first.

Naturally, if you choose to draw more, you don't choose to have a victory.

2• Consider the maximum possible score of the person who is eliminated:

The natural need to first win (n-m-1) Individuals, because they all negative field.

Then he beat half of the people in front of him, because 2*b < a+c.

The last m%2 a draw, or he will beat half of them.

(4) The last case is similar to (3) .

Code:

#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<Set>#include<map>#include<vector>#include<string>#include<queue>#defineLL Long Long#defineMOD 1000000007using namespacestd;intN, M, A, B, C; LL mi, MA;voidinput () {scanf ("%d%d", &n, &m); scanf ("%d%d%d", &a, &b, &c); if(A <c) Swap (A, c);voidWork () {if(b < a && b <c) {mi= (LL) b* (N-1); Ma= (LL) A * (n-m-1); Ma+ = (LL) m/2* (A +c); Ma+ = (LL) c* (m%2);//        return; }    if(b > a && B >c) {ma= (LL) b* (N-1); Mi= (LL) c* (M-1); Mi+ = ((LL) n-m)/2* (A +c); Mi+ = (LL) A * ((n-m)%2);//        return; }    if(2*b < A +c) {mi= (LL) c* (M-1); Mi+ = ((LL) n-m) *b; Ma= (LL) A * (n-m-1); Ma+ = (LL) m/2* (A +c); Ma+ = (LL) b* (m%2);//        return; }    Else{mi= (LL) c* (M-1); Mi+ = ((LL) n-m)/2* (A +c); Mi+ = (LL) b* ((n-m)%2);//Ma= (LL) A * (n-m-1); Ma+ = (LL) m*b; return; }}intMain () {//freopen ("test.in", "R", stdin);    intT; scanf ("%d", &T);  for(intTimes =1; Times <= T; ++Times )        {input ();        Work (); printf ("Case #%d:", times); printf ("%lld%lld\n", MA, MI); }    return 0;}
View Code

ACM Learning process-uvalive 7147 World Cup (category discussion && greed)

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.