P4165 [SCOI2007]组队
Unknown_Error · · 个人记录
题目描述
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在长整型以内。
参考代码:
#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;
}