zoukankan      html  css  js  c++  java
  • Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分

    C. Vasya and Basketball
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer.

    Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that.

    Input

    The first line contains integer n (1 ≤ n ≤ 2·105) — the number of throws of the first team. Then follow n integer numbers — the distances of throws ai (1 ≤ ai ≤ 2·109).

    Then follows number m (1 ≤ m ≤ 2·105) — the number of the throws of the second team. Then follow m integer numbers — the distances of throws of bi (1 ≤ bi ≤ 2·109).

    Output

    Print two numbers in the format a:b — the score that is possible considering the problem conditions where the result of subtraction a - bis maximum. If there are several such scores, find the one in which number a is maximum.

    Examples
    input
    3
    1 2 3
    2
    5 6
    output
    9:6
    input
    5
    6 7 8 9 10
    5
    1 2 3 4 5
    output
    15:10
    思路:我怎么zz的写了个二分;
       n*3-n小于等于d的个数-m*2-m大于d的个数最大;
       显然需要求n小于等于d的个数+m大于d的个数最小;
       我是暴力二分,排个序好像可以把二分取消了;
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    const int N=2e5+10,M=4e6+10,inf=1e9+10,mod=1e9+7;
    const ll INF=1e18+10;
    int a[N],b[N],sa,sb;
    int l[N<<1];
    int flag,n,m;
    int check(int x)
    {
        int pos1=upper_bound(a,a+n,x)-a;
        int pos2=upper_bound(b,b+m,x)-b;
        pos2=m-pos2;
        return pos1+pos2;
    }
    int main()
    {
        flag=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]),l[flag++]=a[i];
        scanf("%d",&m);
        for(int i=0;i<m;i++)
            scanf("%d",&b[i]),l[flag++]=b[i];
        sort(a,a+n);
        sort(b,b+m);
        l[flag++]=0;
        l[flag++]=2e9+1;
        sort(l,l+flag);
        flag=unique(l,l+flag)-l;
        int minn=inf,ans;
        for(int i=0;i<flag;i++)
        {
            int v=check(l[i]);
            if(v<minn)
            {
                minn=v;
                ans=l[i];
            }
        }
        int ji=0,lu=0;
        for(int i=0;i<n;i++)
            if(a[i]<=ans)
                ji++;
        for(int i=0;i<m;i++)
            if(b[i]>ans)
                lu++;
        printf("%d:%d",3*n-ji,2*m+lu);
        return 0;
    }
  • 相关阅读:
    初听余杭...
    生命里走了一位花儿,同时却遇到了10年未见的老同学
    两个馒头过中秋
    周末粉红色的回忆
    jQuery图片剪裁插件 Jcrop
    上周六出去烤肉随便拍了几张
    一周学会Mootools 1.4中文教程:(7)汇总收尾
    30天学会 MooTools 教学(4): 函数和MooTools
    用Mootools寫的一个类似facebook的弹出对话框
    用Mootools获得操作索引的两种方法
  • 原文地址:https://www.cnblogs.com/jhz033/p/5932399.html
Copyright © 2011-2022 走看看