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

    C. Vasya and Basketball

    题目连接:

    http://codeforces.com/contest/493/problem/C

    Description

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

    Sample Input

    3
    1 2 3
    2
    5 6

    Sample Output

    9:6

    Hint

    题意

    A队在n个距离位置投进了篮球,B队在m个位置。

    现在让你来划3分线,然后使得A队分数减去B队分数最大。

    题解:

    暴力枚举三分线,肯定三分线就n+m+4种可能,都暴力枚举一边,然后对于每一个队伍,我二分找到有多少个二分球,和多少个三分球就好了

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 2e5+7;
    int n,m;
    int a[maxn],b[maxn];
    int Ans=-1e9,Ans2,Ans3;
    void update(int x,int y,int z)
    {
        if(Ans<x)Ans=x,Ans2=y,Ans3=z;
        if(Ans==x&&y>Ans2)Ans=x,Ans2=y,Ans3=z;
    }
    void get(int x)
    {
        int l=0,r=m,ans=1;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(b[mid]<=x)ans=mid,l=mid+1;
            else r=mid-1;
        }
        int l2=0,r2=n,ans2=1;
        while(l2<=r2)
        {
            int mid=(l2+r2)/2;
            if(a[mid]<=x)ans2=mid,l2=mid+1;
            else r2=mid-1;
        }
        update(ans2*2+(n-ans2)*3-ans*2-(m-ans)*3,ans2*2+(n-ans2)*3,ans*2+(m-ans)*3);
    }
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        scanf("%d",&m);
        for(int i=1;i<=m;i++)
            scanf("%d",&b[i]);
        sort(a+1,a+1+n);
        sort(b+1,b+1+m);
        update(2*n-2*m,2*n,2*m);
        update(3*n-3*m,3*n,3*m);
        for(int i=1;i<=n;i++)
            get(a[i]);
        get(a[1]-1);
        get(a[n]+1);
        for(int i=1;i<=m;i++)
            get(b[i]);
        get(b[1]-1);
        get(b[m]+1);
        printf("%d:%d
    ",Ans2,Ans3);
    }
  • 相关阅读:
    redis启动
    supervisor thinkphp6 qune
    iview table header cell tooltip; iview表格 表头、单元格文字提示 ;iview 表格 悬浮提示
    .net mvc 中引入 echarts dataTool prepareBoxplotData
    iview table 初始化为null问题
    sqlserver 视图 EF无法从数据更新模型
    sql 空格变问号;sql 无法 去掉 空格 ;sql rtrim 失效;(转载)
    MongoDB的备份与恢复(转载)
    jQuery的deferred对象详解(转载)
    今天,我们小公司的服务器被黑了!!!
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5844267.html
Copyright © 2011-2022 走看看