【bzoj1071】[SCOI2007]组队
2016-09-02 13:23
344 查看
[SCOI2007]组队
DescriptionNBA每年都有球员选秀环节。通常用速度和身高两项数据来衡量一个篮球运动员的基本素质。假如一支球队里
速度最慢的球员速度为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 程序未重测
这道题就是要先给出sum=A*h+B*s排序,然后枚举h和s的最小值。(h – Height, s – Speed)
然后就找两个指针搞
先枚举s最小值,然后一边枚举v的最小值一边查询符合条件的人数,因为这一定是相邻的一串。
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; struct node { LL h,s,sum; }a[5100],b[5100]; int cmp1(const void *xx,const void *yy)//s { node n1=*(node *)xx,n2=*(node *)yy; if(n1.h>n2.h) return 1; if(n1.h<n2.h) return -1; return 0; } int cmp2(const void *xx,const void *yy)//sum { node n1=*(node *)xx,n2=*(node *)yy; if(n1.sum>n2.sum) return 1; if(n1.sum<n2.sum) return -1; return 0; } LL mmin,mmax; int rl(node x)//看一下是否在合理范围内 { if(x.s<=mmax&&x.s>=mmin)return 1; return 0; } LL A,B,C; int main() { freopen("team.in","r",stdin); freopen("team.out","w",stdout); int n; scanf("%d%lld%lld%lld",&n,&A,&B,&C); for(int i=1;i<=n;i++) { scanf("%lld%lld",&a[i].h,&a[i].s); a[i].sum=A*a[i].h+B*a[i].s;b[i]=a[i];//找出sum } qsort(a+1,n,sizeof(node),cmp1);//排序体重 qsort(b+1,n,sizeof(node),cmp2);//排序sum int ans=0; for(int i=1;i<=n;i++) { mmin=a[i].s,mmax=mmin+C/B; //mmin就是找一个s,mmax就是推A * ( height– minH ) + B * ( speed – minV ) <= C 这条公式,最后你就会发现mmax最大只能是mmin+C/B LL l=0,r=0;int cnt=0; for(int j=1;j<=n;j++) { while(r<n&&b[r+1].sum<=A*a[j].h+B*a[i].s+C)cnt+=rl(b[++r]);//如果满足条件 while(l<n&&a[l+1].h<a[j].h)cnt-=rl(a[++l]);//如果比最小的还要小的话 ans=max(ans,cnt); } } printf("%d\n",ans); return 0; }
相关文章推荐
- bzoj1071[SCOI2007]组队
- bzoj1071 [SCOI2007]组队
- bzoj1071: [SCOI2007]组队
- 1071: [SCOI2007]组队 - BZOJ
- bzoj 1071: [SCOI2007]组队
- [单调队列] BZOJ 1071 [SCOI2007]组队
- bzoj1071 [SCOI2007]组队
- [BZOJ1071][SCOI2007][堆]组队
- BZOJ1071 [SCOI2007]组队
- 【bzoj1071】[SCOI2007]组队
- BZOJ 1071 [SCOI2007]组队
- [BZOJ]1071: [SCOI2007]组队 STL优先队列
- 【BZOJ1071】[SCOI2007]组队
- bzoj 1071 [SCOI2007]组队 单调性
- bzoj1071: [SCOI2007]组队
- 【SCOI2007】【BZOJ1071】组队
- BZOJ 1071: [SCOI2007]组队【单调性扫一遍
- BZOJ1071 [SCOI2007]组队
- 【BZOJ1071】【SCOI2007】组队 利用单调性的双指针
- 【bzoj1071】[SCOI2007]组队