zoukankan      html  css  js  c++  java
  • bzoj1071 [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 程序未重测

    正解:计数+单调性。

    我们先把所有人按照高度从小到大排序,然后从大到小枚举高度。

    然后我们把高度$leq$当前高度的人分别按照速度和$a*h+b*s$排序,这里可以用归并排序。

    然后枚举高度,我们发现一个人如果可以在这个队,那么他就要满足$a*h+b*s<=c+a*minh+b*mins$,现在右边已经是一个常数了。

    然后我们可以把满足式子且高度$leq minh$的人加进来,同时每次把高度小于$minh$的人减去。

     1 #include <bits/stdc++.h>
     2 #define il inline
     3 #define RG register
     4 #define ll long long
     5 
     6 using namespace std;
     7 
     8 struct data{ int i; ll h,s,v; }q1[5010],q2[5010],st[5010];
     9 
    10 int vis[5010],n,ans;
    11 ll a,b,c;
    12 
    13 il int gi(){
    14   RG int x=0,q=1; RG char ch=getchar();
    15   while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
    16   if (ch=='-') q=-1,ch=getchar();
    17   while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
    18   return q*x;
    19 }
    20 
    21 il ll gl(){
    22   RG ll x=0,q=1; RG char ch=getchar();
    23   while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
    24   if (ch=='-') q=-1,ch=getchar();
    25   while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
    26   return q*x;
    27 }
    28 
    29 il int cmpx(const data &a,const data &b){ return a.h<b.h; }
    30 
    31 int main(){
    32 #ifndef ONLINE_JUDGE
    33   freopen("team.in","r",stdin);
    34   freopen("team.out","w",stdout);
    35 #endif
    36   n=gi(),a=gl(),b=gl(),c=gl();
    37   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;
    38   sort(q1+1,q1+n+1,cmpx); for (RG int i=1;i<=n;++i) q2[i]=q1[i];
    39   for (RG int p=n;p;--p){
    40     RG ll minx=q1[p].h;
    41     if(p<n){
    42       RG int t1=p,t2=p+1;
    43       for (RG int i=1;i<=n-p+1;++i)
    44     if (t2>n || (t2<=n && t1<=p && q1[t1].s<q1[t2].s)) st[i]=q1[t1++]; else st[i]=q1[t2++];
    45       for (RG int i=p;i<=n;++i) q1[i]=st[i-p+1]; t1=p,t2=p+1;
    46       for (RG int i=1;i<=n-p+1;++i)
    47     if (t2>n || (t2<=n && t1<=p && q2[t1].v<q2[t2].v)) st[i]=q2[t1++]; else st[i]=q2[t2++];
    48       for (RG int i=p;i<=n;++i) q2[i]=st[i-p+1];
    49     }
    50     for (RG int i=p,pos=p,res=0;i<=n;++i){
    51       RG ll lim=c+a*minx+b*q1[i].s;
    52       while (pos<=n && q2[pos].v<=lim){
    53     if (q2[pos].s>=q1[i].s) ++res,vis[q2[pos].i]=1; ++pos;
    54       }
    55       ans=max(ans,res); if (vis[q1[i].i]) --res,vis[q1[i].i]=0;
    56     }
    57   }
    58   cout<<ans; return 0;
    59 }
  • 相关阅读:
    原创:Qt自定义拖放
    看下最近公司的招聘需求
    leveldb阅读心得
    Relationship between the FIX Protocol's OrdID, ClOrdID, OrigClOrdID?
    Wait Functions
    全局变量与单例模式
    Asynchronous I/O
    QuickFix MsgHandler
    第一个Java程序
    (原創) Function Pointer、Delegate和Function Object (C/C++) (template) (.NET) (C#)
  • 原文地址:https://www.cnblogs.com/wfj2048/p/7663308.html
Copyright © 2011-2022 走看看