• 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.

    Sample test(s)
    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

     题意: 给出两个球队进球的距离,要你选择一个距离d ,进球距离 <= d 的进球得两分,大于的得三分

    问你a队得分-b队得分的最大差距。

    思路: d是进球距离里面的某个数,然后我们可以先离散化距离,然后枚举d,

    枚举的时候用树状数组计算两只球队得分。

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<queue>
    #include<set>
    #include<algorithm>
    #define maxn 400010
    #define INF 0x3f3f3f3f
    using namespace std ;
    
    int xt[2][maxn] ,sz;
    int a[200010],b[200010],num[maxn] ;
    
    void insert(int id,int x)
    {
        while(x<=sz)
        {
            xt[id][x]++;
            x += (x&-x) ;
        }
    }
    int sum(int id,int x)
    {
        int ans=0;
        while(x>0)
        {
            ans += xt[id][x] ;
            x -= (x&-x) ;
        }
        return ans;
    }
    
    int main()
    {
        int i,j,n,m,k ;
        int xx,yy,x,y;
        int t1,t2;
        while(scanf("%d",&n) != EOF)
        {
            memset(xt,0,sizeof(xt));
            sz=0;
            for( i = 1 ; i <= n ;i++)
            {
                scanf("%d",&a[i]) ;
                num[sz++]=a[i] ;
            }
            scanf("%d",&m) ;
            for( i = 1 ; i <= m ;i++)
            {
                scanf("%d",&b[i]) ;
                num[sz++]=b[i] ;
            }
            sort(num,num+sz) ;
            sz=unique(num,num+sz)-num ;
            for( i = 1 ; i <= n;i++)
            {
                x=lower_bound(num,num+sz,a[i])-num;
                insert(0,x+1) ;
            }
            for( i = 1 ; i <= m;i++)
            {
                x=lower_bound(num,num+sz,b[i])-num;
                insert(1,x+1) ;
            }
            xx=-INF;
            yy=0;
            for( i = -1 ; i < sz ;i++)
            {
                x=sum(0,i+1);
                y=sum(1,i+1);
                t1=x*2+(n-x)*3;
                t2=y*2+(m-y)*3;
                if(t1-t2>xx-yy||(t1-t2==xx-yy&&t1>xx))
                {
                    xx=t1;yy=t2;
                }
            }
            printf("%d:%d
    ",xx,yy) ;
        }
        return 0 ;
    }
    View Code
  • 相关阅读:
    (转)PHP 的 __FILE__ 常量
    smarty半小时快速上手教程(转)
    Namespace declaration statement has to be the very first
    ThinkPhp3.2 无法加载模块:Index
    注意mysql中的编码格式和php中的编码格式一致
    MySQL数据库备份与恢复方法(转)
    phpmyadmin设置id自增(AUTO_INCREMENT)(转)
    (转)用eclipse创建一个j2ee的web工程后,左面projects窗口中的项目如何没有显示webRoot文件夹,除了src的文件夹,其他都不显示
    CentOS6.8 安装 Nginx
    Eclipse Java注释模板设置详解
  • 原文地址:https://www.cnblogs.com/20120125llcai/p/4142206.html
Copyright © 2020-2023  润新知