bzoj1071 [SCOI2007]组队
2017-10-24 22:24
204 查看
Description
NBA每年都有球员选秀环节。通常用速度和身高两项数据来衡量一个篮球运动员的基本素质。假如一支球队里速度最慢的球员速度为minV,身高最矮的球员高度为minH,那么这支球队的所有队员都应该满足: A * ( height – minH ) + B * ( speed – minV ) <= C 其中A和B,C为给定的经验值。这个式子很容易理解,如果一个球队的球员速度和身高差距太大,会造成配合的不协调。 请问作为球队管理层的你,在N名选秀球员中,最多能有多少名符合条件的候选球员。Input
第一行四个数N、A、B、C 下接N行每行两个数描述一个球员的height和speedOutput
最多候选球员数目。Sample Input
4 1 2 105 1
3 2
2 3
2 1
Sample Output
4HINT
数据范围: N <= 5000 ,height和speed不大于10000。A、B、C在长整型以内。2016.3.26 数据加强 Nano_ape 程序未重测
正解:计数+单调性。
我们先把所有人按照高度从小到大排序,然后从大到小枚举高度。
然后我们把高度$\leq$当前高度的人分别按照速度和$a*h+b*s$排序,这里可以用归并排序。
然后枚举高度,我们发现一个人如果可以在这个队,那么他就要满足$a*h+b*s<=c+a*minh+b*mins$,现在右边已经是一个常数了。
然后我们可以把满足式子且高度$\leq minh$的人加进来,同时每次把高度小于$minh$的人减去。
#include <bits/stdc++.h> #define il inline #define RG register #define ll long long using namespace std; struct data{ int i; ll h,s,v; }q1[5010],q2[5010],st[5010]; int vis[5010],n,ans; ll a,b,c; il int gi(){ RG int x=0,q=1; RG char ch=getchar(); while ((ch<'0' || ch>'9') && ch!='-') ch=getchar(); if (ch=='-') q=-1,ch=getchar(); while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar(); return q*x; } il ll gl(){ RG ll x=0,q=1; RG char ch=getchar(); while ((ch<'0' || ch>'9') && ch!='-') ch=getchar(); if (ch=='-') q=-1,ch=getchar(); while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar(); return q*x; } il int cmpx(const data &a,const data &b){ return a.h<b.h; } int main(){ #ifndef ONLINE_JUDGE freopen("team.in","r",stdin); freopen("team.out","w",stdout); #endif n=gi(),a=gl(),b=gl(),c=gl(); for (RG int i=1;i<=n;++i) q1[i].i=i,q1[i].h=gl(),q1[i].s=gl(),q1[i].v=a*q1[i].h+b*q1[i].s; sort(q1+1,q1+n+1,cmpx); for (RG int i=1;i<=n;++i) q2[i]=q1[i]; for (RG int p=n;p;--p){ RG ll minx=q1[p].h; if(p<n){ RG int t1=p,t2=p+1; for (RG int i=1;i<=n-p+1;++i) if (t2>n || (t2<=n && t1<=p && q1[t1].s<q1[t2].s)) st[i]=q1[t1++]; else st[i]=q1[t2++]; for (RG int i=p;i<=n;++i) q1[i]=st[i-p+1]; t1=p,t2=p+1; for (RG int i=1;i<=n-p+1;++i) if (t2>n || (t2<=n && t1<=p && q2[t1].v<q2[t2].v)) st[i]=q2[t1++]; else st[i]=q2[t2++]; for (RG int i=p;i<=n;++i) q2[i]=st[i-p+1]; } for (RG int i=p,pos=p,res=0;i<=n;++i){ RG ll lim=c+a*minx+b*q1[i].s; while (pos<=n && q2[pos].v<=lim){ if (q2[pos].s>=q1[i].s) ++res,vis[q2[pos].i]=1; ++pos; } ans=max(ans,res); if (vis[q1[i].i]) --res,vis[q1[i].i]=0; } } cout<<ans; return 0; }
相关文章推荐
- 【bzoj1071】[SCOI2007]组队
- 【BZOJ1071】【SCOI2007】组队 利用单调性的双指针
- 【BZOJ1071】[SCOI2007]组队
- 【bzoj1071】[SCOI2007]组队
- bzoj1071: [SCOI2007]组队
- BZOJ1071 [SCOI2007]组队
- [BZOJ]1071: [SCOI2007]组队 STL优先队列
- 【BZOJ1071】【SCOI2007】组队 利用单调性的双指针
- BZOJ 1071: [SCOI2007]组队【单调性扫一遍
- 【bzoj1071】[SCOI2007]组队
- bzoj 1071: [SCOI2007]组队 (单调性乱搞)
- BZOJ 1071([SCOI2007]组队-双指针)
- [单调队列] BZOJ 1071 [SCOI2007]组队
- 1071: [SCOI2007]组队 - BZOJ
- BZOJ 1071 [SCOI2007]组队
- bzoj1071[SCOI2007]组队
- bzoj1071 [SCOI2007]组队
- bzoj 1071 [SCOI2007]组队 单调性
- bzoj1071: [SCOI2007]组队
- BZOJ1071 [SCOI2007]组队