跳到正文

个人记录

P4165 [SCOI2007]组队

Unknown_Error约 3 分钟
原文
文章信息与版本

文章信息

发布
2018年1月29日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 3 分钟

版本

  1. v1当前

题目描述

NBA每年都有球员选秀环节。通常用速度和身高两项数据来衡量一个篮球运动员的基本素质。假如一支球队里速度最慢的球员速度为minV,身高最矮的球员高度为minH,那么这支球队的所有队员都应该满足: A × ( height – minH ) + B × ( speed – minV ) <= C 其中A和B,C为给定的经验值。这个式子很容易理解,如果一个球队的球员速度和身高差距太大,会造成配合的不协调。

请问作为球队管理层的你,在N名选秀球员中,最多能有多少名符合条件的候选球员。

输入输出格式

输入格式:

第一行四个数N、A、B、C 下接N行每行两个数描述一个球员的height和speed

输出格式:

最多候选球员数目。

输入输出样例

输入样例#1:##

4 1 2 10

5 1 3 2 2 3 2 1

输出样例#1:

4

说明

数据范围: N <= 5000 ,height和speed不大于10000。A、B、C在长整型以内。

参考代码:

C++
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
struct node{
    LL x,y,sum;
}a[51000],b[51000];
LL A,B,C,ans;
int n;
int cmpx(const void *xx,const void *yy){
    node n1=*(node*)xx;
    node n2=*(node*)yy;
    return n1.x-n2.x;
}
int cmpsum(const void *xx,const void *yy){
    node n1=*(node*)xx;
    node n2=*(node*)yy;
    return n1.sum-n2.sum;
}
typedef long long LL;
int main(){
    int n;scanf("%d%lld%lld%lld",&n,&A,&B,&C);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&a[i].x,&a[i].y);
        a[i].sum=A*a[i].x+B*a[i].y;
        b[i]=a[i];
    }
    qsort(a+1,n,sizeof(node),cmpx);
    qsort(b+1,n,sizeof(node),cmpsum);
    int ans=0;
    for(int i=1;i<=n;i++){
        LL low2=a[i].y,high=low2+C/B,l=0,r=0;
        int sum=0;
        for(int j=1;j<=n;j++){
            LL low1=a[j].x;
            while(r<n&&b[r+1].sum<=A*low1+B*low2+C){
                r++;if(b[r].y<=high&&b[r].y>=low2)sum++;
            }
            while(l<n&&a[l+1].x<low1){
                l++;if(a[l].y<=high&&a[l].y>=low2)sum--;
            }
            ans=max(ans,sum);
        }
    }
    printf("%d\n",ans);
    return 0;
}
原文
存档评论2 条抓取于