Codeforces #281 (Div. 2)C Vasya and Basketball(二分)

题目链接:【戳】

题意相对比较简单,两个人比赛篮球投篮,与正常的篮球比赛不同的是,三分线与篮筐的距离d是不确定的。输入第一个人投了n个球,n个球每个球投的时候他与篮筐的距离;然后输入第二个人头了m个球,m个球每个球投的时候他与篮筐的距离。

然后让你选择一个d,使得它对于第一个人最为有利,所谓有利即使得“第一个人的分数-第二个人的分数”最大,将比分输出。当有多个相同的最大差值的情况时,输出第一个人分数最大的那组。

只要对于枚举的一个距离x,每个人得到的分数则可以表示成:(比x近的个数)*2 + (比x远的个数)*3

所以只需要枚举(m+n+1)种情况,然后分别二分找到枚举的距离在n个球和m个球中的排第几,即可算出两者分差。

代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
LL a[200010], b[200010], c[400010];
int t, n, m;
int main() {
    scanf("%d", &n);
    int num = 1;
    for(int i = 1; i <= n; i++) {
        scanf("%I64d", &a[i]);
        c[num++] = a[i];
    }
    sort(a+1, a+n+1);
    scanf("%d", &m);
    for(int i = 1; i <= m; i++) {
        scanf("%I64d", &b[i]);
        c[num++] = b[i];
    }
    sort(b+1, b+m+1);
    sort(c+1, c+num);
    LL ans = (LL)(-1e10);
    LL x, y;
    if(ans < n * 2 - m * 2) {
        x = (LL)n * 2;
        y = (LL)m * 2;
        ans = x - y;
    }
    for(int i = num - 1; i >= 0; i--) {
        //cout<<c[i]<<endl; 小于等于个数
        int tmp1 = upper_bound(a+1, a+n+1, c[i]) - a - 1;
        int tmp2 = upper_bound(b+1, b+m+1, c[i]) - b - 1;
        //cout<<tmp1 << "  "<< tmp2<<endl;
        if(ans <= (LL)tmp1*2+(LL)(n-tmp1)*3 - (LL)tmp2*2-(LL)(m-tmp2)*3) {
            x = (LL)tmp1*2+(LL)(n-tmp1)*3;
            y = (LL)tmp2*2+(LL)(m-tmp2)*3;
            ans = x - y;
        }
    }
    cout<<x<<":"<<y<<endl;
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值