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;
    }
  • 相关阅读:
    趣谈编程史第4期-饱受争议的前端之王JavaScript的血泪成长史
    趣谈编程史第2期-这个世界缺少对C语言的敬畏,你不了解的C语言科普
    趣谈编程史第1期-跌宕起伏的java帝国史,剖析谷歌甲骨文长达8年的版权战争
    记录一次Metaspace扩容引发FGC的调优总结
    多线程学习笔记-深入理解ThreadPoolExecutor
    使用CompletableFuture优化你的代码执行效率
    Linux+Shell常用命令总结
    Guava Cache探索及spring项目整合GuavaCache实例
    将List按照指定大小等分的几种实现方式和效率对比及优化
    Spring的事件机制详解
  • 原文地址:https://www.cnblogs.com/jhz033/p/5932399.html
Copyright © 2011-2022 走看看