# Codeforces Round #311 (Div. 2)

Source: Internet
Author: User

Water A-ilya and diplomas

`#include <cstdio> #include <cstring> #include <algorithm> #include <iostream>using namespace Std;int A[4];int Main (void)  {    int n;  CIN >> N;    int Mn1, MX1, Mn2, MX2, Mn3, mx3;    CIN >> mn1 >> mx1;    CIN >> Mn2 >> MX2;    CIN >> mn3 >> mx3;    A[3] = Mn3; A[2] = Mn2;    int res = n-a[2]-a[3];    if (res <= mx1) a[1] = res;    else    {        a[1] = mx1; Res-= a[1];        if (A[2] + res <= MX2)  a[2] + = res;        else    {            a[2] = MX2; A[3] + = (RES-(a[2]-Mn2));}    }    cout << a[1] << "<< a[2] <<" "<< a[3] << Endl;    return 0;}`

Greed | | Dichotomy B-pasha and Tea

Test instructions: There are n girl and N boy tea, cup capacity, boy drink is girl twice times and boy drink as much, girl drink as much, ask Master can pour out how much water

Analysis: The first reaction is to use two-point search girl drink tea capacity, unfortunately write rubbing, mid should and the minimum amount of tea girl and boy to compare. Read the code 99% is greedy, dizzy ~

Code (two points):

```#include <cstdio> #include <algorithm> #include <cstring> #include <iostream>using namespace std;const int N = 1e5 + 10;const int INF = 0x3f3f3f3f;const double EPS = 1e-9;int a[n*2];int main (void)  {    int n;
int W;   scanf ("%d%d", &n, &w);    n *= 2;    for (int i=1; i<=n; ++i)  {        scanf ("%d", &a[i]);    }    Sort (a+1, a+1+n);    Double L = 0.0, r = w;    Double mid = 0.0, ans = 0.0;    for (int i=1; i<=100; ++i)   {        mid = (L + r)/2.0;        If (Mid >= 0 && mid <= a[1] && mid * 2 <= a[n/2+1] && mid * 1.5 * n <= W)    {            L = Mid;            Ans = Mid * 1.5 * n;        }        else    r = Mid;    }    printf ("%.6f\n", ans);    return 0;}```

Code (GREEDY):

`#include <cstdio> #include <algorithm> #include <cstring> #include <iostream>using namespace std;const int n = 1e5 + 10;int a[n*2];int main (void)  {    int n, W;   scanf ("%d%d", &n, &w);    n *= 2;    for (int i=1; i<=n; ++i)    scanf ("%d", &a[i]);    Sort (a+1, a+1+n);    Double ans = min (a[1] * 1.0, A[N/2+1]/2.0);    ans = min (ans * 3 * n/2.0, W * 1.0);    printf ("%.6f\n", ans);    return 0;}`

Not to be continued ~

Codeforces Round #311 (Div. 2)

Related Keywords:

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.