bzoj1071 [SCOI2007]组队(枚举+单调队列)

这题我哪会呀。题解:portal

#include 
#include 
#include 
#include 
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 5010
inline char gc(){
    static char buf[1<<16],*S,*T;
    if(S==T){T=(S=buf)+fread(buf,1,1<<16,stdin);if(T==S) return EOF;}
    return *S++;
}
inline ll read(){
    ll x=0,f=1;char ch=gc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc();
    return x*f;
}
int n,ans=0;
ll A,B,C,Sum;
struct data{
    int h,s;ll sum;
}a[N],b[N];
inline bool cmp1(data a,data b){return a.hinline bool cmp2(data a,data b){return a.sumint main(){
//  freopen("a.in","r",stdin);
    n=read();A=read();B=read();C=read();
    for(int i=1;i<=n;++i) a[i].h=read(),a[i].s=read(),a[i].sum=A*a[i].h+B*a[i].s,b[i]=a[i];
    sort(a+1,a+n+1,cmp1);sort(b+1,b+n+1,cmp2);
    for(int j=1;j<=n;++j){//枚举s最小值
        int s=a[j].s,p1=1,p2=1,cnt=0,mx=s+C/B;
        for(int i=1;i<=n;++i){//枚举h最小值
            Sum=C+A*a[i].h+B*s;
            while(p2<=n&&b[p2].sum<=Sum) cnt+=(b[p2].s>=s&&b[p2].s<=mx),++p2;
            while(p1<=n&&a[p1].h=s&&a[p1].s<=mx),++p1;
            ans=max(ans,cnt);
        }
    }printf("%d\n",ans);
    return 0;
}

你可能感兴趣的:(bzoj,单调队列,暴力)