• Codeforces Round #281 (Div. 2) C. Vasya and Basketball 排序


    C. Vasya and Basketball
     

    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 subtractiona - b is maximum. If there are several such scores, find the one in which number a is maximum.

    Sample test(s)
    input
    3
    1 2 3
    2
    5 6
    output
    9:6
    题意:投篮比赛,给你两个人投进篮球的距离,让你找到一个d使得小于等于d的距离的投篮得分为2,大于d的距离得分为3,同时使得a-b得分差最大
            如果有a-b相同的情况,尽量使a最大
    题解:按照分差排序同时a尽量大,就行了
    ///meek
    #include<bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    #define mem(a) memset(a,0,sizeof(a))
    #define pb push_back
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')f=-1;ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=x*10+ch-'0';ch=getchar();
        }return x*f;
    }
    //****************************************
    const int N=2000005;
    #define mod 10000007
    #define inf 2000000007
    #define maxn 10000
    
    ll lna,lnm,n,a[N],b[N],m;
    
    struct ss{
      ll x,in,index;
    }s[N+N];
    struct sss {
        ll x,aa;
        int in;
    }W[N+N];
    int cmp(ss s1,ss s2)  {
        if(s1.x==s2.x) return s1.in<s2.in;
        return s1.x<s2.x;
    }
    int cmp2(sss s1,sss s2)  {
        if(s1.x==s2.x) return s1.aa<s2.aa;
       else return s1.x<s2.x;
    }
    int main() {
    
         n=read();
        int k=0;
        for(int i=1;i<=n;i++) {
            scanf("%I64d",&a[i]);
            s[++k].x=a[i];
            s[k].in=0;
            s[k].index=i;
        }
        m=read();
        for(int i=1;i<=m;i++) {
            scanf("%I64d",&b[i]);
             s[++k].x=b[i];
            s[k].in=1;
            s[k].index=i;
        }
        sort(s+1,s+k+1,cmp);
        ll l=0,r=0;
        for(int i=1;i<=k;i++) {
            if(s[i].in==0) {
                l++;
            }
            else r++;
            W[i].x=(l*2+(n-l)*3)-(r*2+(m-r)*3);
            W[i].aa=(l*2+(n-l)*3);
            W[i].in=i;
        }
        W[++k].x=n*3-m*3;
        W[k].aa=(n*3);
        W[k].in=-1;
         W[++k].x=n*2-m*2;
        W[k].aa=(n*2);
        W[k].in=-2;
        sort(W+1,W+k+1,cmp2);
        ll ansl=0,ansr=0;
        ansl=W[k].aa;ansr=W[k].aa-W[k].x;
        cout<<ansl<<":"<<ansr<<endl;
        return 0;
    }
    代码
  • 相关阅读:
    如何使用php实现首页和子页面之间的交互
    用php实现,打开哪个页面哪个页面就有默认的样式
    后台链接前台有关显示不显示
    上传文件的最大值,post传值的最大值得修改
    linux 操作系统的安装,本地登录及远程登录,vnc连接操作详细步骤
    滑动组件
    Numpy简介
    java对象序列化
    集合类操作需要注意的地方
    TreeMap详解
  • 原文地址:https://www.cnblogs.com/zxhl/p/4979306.html
Copyright © 2020-2023  润新知