Codeforces 557B. Pasha and Tea Problem solving report

Source: Internet
Author: User

Title Link: Http://codeforces.com/problemset/problem/557/B

Title meaning: There are 2n cups, which stipulates that the first cup can only be filled with ai ml of water. Now give the W ml of water, you need to put this w ml (Can not light) water into the 2n cup, so that the water to the n male each water is exactly twice times the n female (note that N Men's water Cup is the same, n female is also). The question now is how to make 2n cups of water the most, to find out the value.

(Start to mislead others, ignore them)

Assuming that the water poured into the girl's Cup is x ml, I do a direct list of two inequalities, and then take a smaller value * 3n (NX is all women's water, 2NX is all men), so it has been unable to pretest 8.

(1) 2*x≤ Cup maximum capacity (AI maximum)

(2) nx+ 2nx≤w (not more than w ml of water bar)

This is wrong .... The first (1) type is not listed! Imagine, assuming that the Water Cup number is 1~2n, because the first n small water cups are divided for girls, which indicates that the post-n-Large water cup is divided for boys. But the boy can only take the water for the n+1 capacity, because the capacity of each cup is limited ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ so we need to sort, find the big n+1. I thought I'd use two points to do it at first. = =

*********************************************

The correct way of thinking is to be discussed in a sub-situation!

We need to take out a[1] and a[n+1] to discuss the AI after the order is finished. That is, the minimum cup capacity (X) and the N+1 Water cup capacity Y. Because the best solution is to assign X to each girl, Y is assigned to each boy.

Note that they may be twice times the relationship or not. So it's natural to discuss .... The size relationship between 2x and Y!

(1) 2x≤y said can be x ml of water to girls, 2x points to boys, anyway 2x certainly not greater than Y

Total allocated water: xn + 2xn = 3xn

(2) 2x > y at this time we can only y/2 ml of water to girls (do not say must be divided into the water for girls x ml, Y/2 certainly smaller than X, inequality of their own shift to see BAI)

Total allocated water: Y/2 * n + y * n = 1.5 yn

Of course, we can not be more than the given W ml, so the last to take a smaller value as the answer

  

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <algorithm>6 using namespacestd;7 8 Const intMAXN = 2e5 +5;9 intA[MAXN];Ten  One intMain () A { - #ifndef Online_judge -Freopen ("In.txt","R", stdin); the     #endif //Online_judge -  -     intN, W; -      while(SCANF ("%d%d", &n, &w)! =EOF) { +  -          for(inti =0; I <2*n; i++) { +scanf"%d", &a[i]); A         } atSort (A, a+n+n); -         intMAXV =A[n]; -         intMINV = a[0]; -  -         DoubleAns =0.0; -         if(minv*2>MAXV) { inAns = (Double) MAXV * n *1.5;//MAXV/2 * n + maxv * N; -         } to  +         Else { -Ans = (Double) MINV * n *3.0; the         } *printf"%.9lf\n", Min (w*1.0) , ans); $     }Panax Notoginseng     return 0; -}
View Code

Codeforces 557B. Pasha and Tea Problem solving report

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.