Description
NBA每年都有球员选秀环节。通常用速度和身高两项数据来衡量一个篮球运动员的基本素质。假如一支球队里
速度最慢的球员速度为minV,身高最矮的球员高度为minH,那么这支球队的所有队员都应该满足: A * ( height – minH )
+ B * ( speed – minV ) <= C 其中A和B,C为给定的经验值。这个式子很容易理解,如果一个球队的 球员速度和身高差距太大,会造成配合的不协调。 请问作为球队管理层的你,在N名选秀球员中,最多能有多少名 符合条件的候选球员。
Input
第一行四个数N、A、B、C 下接N行每行两个数描述一个球员的height和speed
Output
最多候选球员数目。
Sample Input
4 1 2 10
5 1
3 2
2 3
2 1
Sample Output
4
HINT
数据范围: N <= 5000 ,height和speed不大于10000。A、B、C在长整型以内。
2016.3.26 数据加强 Nano_ape 程序未重测
题解
好题啊毒瘤题啊思维题
全程%大佬
主要就是借助一个思维。。先加入speed满足条件的,后删除height不满足条件的。这样就完美了
具体题解可以看我上面发的那个
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
struct node
{
LL h,s,tmp;
}a1[5100],a2[5100],a3[5100];
int n;LL A,B,C;
bool cmp1(node n1,node n2){return n1.tmp<n2.tmp;}
bool cmp2(node n1,node n2){return n1.h<n2.h;}
bool cmp3(node n1,node n2){return n1.s<n2.s;}
int main()
{
scanf("%d%lld%lld%lld",&n,&A,&B,&C);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&a1[i].h,&a1[i].s);a1[i].tmp=A*a1[i].h+B*a1[i].s;
a2[i]=a3[i]=a1[i];
}
sort(a1+1,a1+1+n,cmp1);
sort(a2+1,a2+1+n,cmp2);
sort(a3+1,a3+1+n,cmp3);
int ans=0;
for(int i=1;i<=n;i++)//枚举v
{
int l=0,r=0,cnt=0;
LL minv=a3[i].s;
LL limv=minv+C/B;
for(int j=1;j<=n;j++)//枚举h
{
LL limtmp=C+A*a2[j].h+B*a3[i].s;
while(r+1<=n && a1[r+1].tmp<=limtmp)
{
r++;
if(minv<=a1[r].s && a1[r].s<=limv)cnt++;
}
while(l+1<=n && a2[l+1].h<a2[j].h)
{
l++;
if(minv<=a2[l].s && a2[l].s<=limv)cnt--;
}
ans=max(ans,cnt);
}
}
printf("%d\n",ans);
return 0;
}