LA7147 World Cup Math

Source: Internet
Author: User
Tags min

Topic links

Test instructions: Given sample number T

Number of teams given N, number of qualifying teams m

Given A,b,c (for winning, draw, or losing points respectively)

The maximum number of points that can be obtained, and the smallest possible score to qualify for promotion, respectively.

Idea: Consider the maximum possible score that cannot be promoted, (1) B>=max (a,c) so max= (n-1) *b; (2) B<max (A,C), then first we have to let the former (m+1) team dump

Open the back of the team, that is, Max was initially (N-M-1) *max (a,c), and then the former (m+1) team to carry out M-game, in order to get the most points can not be promoted, then this (m+1) detachment

To the extent possible, that is, to win a losing one, set the current stage of a team to win the X-field, then for each troop in this stage can be divided into ax+ (m-2x) b+cx,0<=x<=m/2;

If a+c>=2b, x take M/2; When a+c<2b, X takes 0. When M is an odd number, it is necessary to calculate the fraction of this stage before the special treatment, namely Max+=max (B,min (A,C)), which is

For this reason can not be guaranteed to win a time to lose one, so for can not qualify through a defeat can lead to not qualify, to take min (a,c), but can be a draw (that is, m+1

The detachment is the same as the section M score), so the summation of the special sentence is Max (B,min (a,c)). Can be promoted to obtain the smallest score can also be similar to the introduction, after consideration (N-M+1) detachment

(B,max (A,c)). See the code:

/********************************************************* file Name:LA7147.cpp Author:kereo create time:2015 year 0 April 30 Thursday 16:41 22 sec *********************************************************/#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <set> #include <map> #include < vector> #include <stack> #include <cmath> #include <string> #include <algorithm> using
namespace Std;
typedef long Long LL;
const int sigma_size=26;
const int N=100+50;
const int MAXN=100000+50;
const int INF=0X3FFFFFFF;
const double eps=1e-8;
const int mod=1000000000+7;
#define L (x) (x<<1) #define R (x) (x<<1|1) #define PII pair<int, int> #define MK (x, y) Make_pair (())
ll N,m,a,b,c;
	int main () {//freopen ("In.txt", "R", stdin);
	int t,kase=0;
	scanf ("%d", &t);
		while (t--) {scanf ("%lld%lld", &n,&m);
		scanf ("%lld%lld%lld", &a,&b,&c);
		ll Ans1,ans2; if (B>=max (a,c)) ans1= (n1) *b;
			else{ans1= (n-m-1) *max (A,C);
			int k=m;
				if (k%2 = = 1) {k--;
			Ans1+=max (B,min (a,c));
			} if (a+c>=2*b) ans1+= (a+c-2*b) *k/2+b*k;
		else Ans1+=b*k;
		} if (B<=min (a,c)) ans2= (n-1) *b;
			else{ans2= (m-1) *min (A,C);
			int k=n-m;
				if (k%2 = = 1) {k--;
			Ans2+=min (B,max (a,c));
			} if (a+c>=2*b) ans2+=b*k;

		else ans2+= (a+c-2*b) *k/2+b*k;

	} printf ("Case #%d:%lld%lld\n", ++kase,ans1,ans2);
} return 0; }



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.