您的位置:首页 > 其它

【bzoj1071】[SCOI2007]组队

2017-11-09 08:16 253 查看

1071: [SCOI2007]组队

Time Limit: 3 Sec  Memory Limit: 128 MB
Submit: 2428  Solved: 773

[Submit][Status][Discuss]

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



[Submit][Status][Discuss]


SCOI系列

比较显然的一道题

拿到这题的第一个想法肯定是枚举minh和minv

那么我们将height和speed两个数组排序

再将式子变换一下,得

A * height + B * speed <= C + A * minH + B * minV

考虑到对于当前所有高度大于minH并且速度大于minV的球员个数是为满足上式的个数,

那么我们可以开一个桶存球员个数,于是上式就成了一个区间查询

继续发现,右式在我们枚举minH时是递减的,于是我们可以不用区间查询直接标记一下即可

代码:

#include<cstdio>
#include<ctime>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<bitset>
#include<cstring>
#include<queue>
using namespace std;

typedef long long LL;

const int maxn = 5010;

struct data{
LL x; int id;
}h[maxn],s[maxn];

queue<LL> Q;
LL n,a,b,c,datax[maxn],ha[maxn],tot,d[maxn],cnt[maxn],sum[maxn];
int ans;

inline int getint()
{
int ret = 0;
char c = getchar();
while (c < '0' || '9' < c) c = getchar();
while ('0' <= c && c <= '9')
ret = ret * 10 + c - '0',c = getchar();
return ret;
}

inline bool cmp(data a,data b)
{
return a.x < b.x;
}

int main()
{
n = getint(); a = getint(); b = getint(); c = getint();
for (int i = 1; i <= n; i++)
{
h[i].id = s[i].id = i;
h[i].x = getint(); s[i].x = getint();
datax[i] = d[i] = a * h[i].x + b * s[i].x;
}
sort(datax + 1,datax + n + 1);
for (int i = 1; i <= n; i++)
if (datax[i] != datax[i + 1])
ha[++tot] = datax[i];
for (int i = 1; i <= n; i++)
d[i] = lower_bound(ha + 1,ha + tot + 1,d[i]) - ha;

sort(h + 1,h + n + 1,cmp); sort(s + 1,s + n + 1,cmp);
for (int i = n; i >= 1; i--) //h
{
memset(cnt,0,sizeof(cnt));
memset(sum,0,sizeof(sum));
for (int j = i; j <= n; j++) cnt[h[j].id]++;
int now = tot,cal = 0;
for (int j = n; j >= 1; j--) //s
{
while (ha[now] > c + a * h[i].x + b * s[j].x) cal -= sum[now] , sum[now--] = 0;
cnt[s[j].id]++;
if (cnt[s[j].id] == 2 && ha[d[s[j].id]] <= c + a * h[i].x + b * s[j].x)
sum[d[s[j].id]]++ , cal++;
ans = max(ans,cal);
}
}
printf("%d",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: