BZOJ 1071 [SCOI2007]组队

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 程序未重测

 

Source

 

高效题解

据说是基于单调性的(n^2)乱搞

屠龙宝刀点击就送

#include <algorithm>
#include <cstdio>
#include <cctype>
#define N 10005

using namespace std;
typedef long long LL;
LL n,a,b,c,h[N],s[N];
inline void read(LL &x)
{
    register char ch=getchar();
    for(x=0;!isdigit(ch);ch=getchar());
    for(;isdigit(ch);x=x*10+ch-'0',ch=getchar());
}
struct node
{
    LL h,s,sum;
}x[N],y[N];
bool cmp(node a,node b) {return a.h<b.h;}
bool comp(node a,node b) {return a.sum<b.sum;}
int main(int argc,char *argv[])
{
    read(n);read(a);read(b);read(c);
    for(int i=1;i<=n;++i)
    {
        read(x[i].h);
        read(x[i].s);
        x[i].sum=x[i].h*a+x[i].s*b;
        y[i]=x[i];
    }
    sort(x+1,x+1+n,cmp);
    sort(y+1,y+1+n,comp);
    LL Min,Max;
    int ans=0;
    for(int i=1;i<=n;++i)
    {
        int l=0,r=0,cnt=0;
        Min=x[i].s,Max=Min+c/b;
        for(int j=1;j<=n;++j)
        {
            while(r<n&&y[r+1].sum<=a*x[j].h+b*x[i].s+c)
             ++r,cnt+=(y[r].s<=Max&&y[r].s>=Min);
            while(l<n&&x[l+1].h<x[j].h)
             ++l,cnt-=(x[l].s<=Max&&x[l].s>=Min);
            ans=cnt>ans?cnt:ans;
        }
    }
    printf("%d\n",ans);
    return 0;
}

 

posted @ 2017-10-19 22:04  杀猪状元  阅读(189)  评论(0编辑  收藏  举报