【BZOJ1071】[SCOI2007]组队

18 篇文章 0 订阅
4 篇文章 0 订阅

【BZOJ1071】[SCOI2007]组队

Time Limit: 3 Sec Memory Limit: 128 MB
Submit: 2216 Solved: 692

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]

思路

这道题可以 O(nlog2n) 复杂度处理。

题目的意思是求满足 A(ai.hhmin)+B(ai.ssmin)C 的最大个数。既然要求这个的话那可以在读入每个 ai.h 的时候乘以一个A,读入每个 ai.s 的时候乘以一个B,然后既然要按照上文不等式中左边两项的和比较,不妨设一个 ai.v 表示 (ai.s+ai.h)

循环 i ,按照ai.s从小到大排序,用 ai.s smin ,同时更新 hmin ,对于堆中的某个 x ,如果x.v>C+hmin+smin那么把 x 移除堆。答案就是最后堆中元素个数的最小值。

这样,按照上文的循环逻辑,最坏复杂度O(nlog2n)

代码

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>

int nextInt()
{
    int num = 0;
    char c;
    bool flag = false;
    while ((c = std::getchar()) == ' ' || c == '\r' || c == '\t' || c == '\n');
    if (c == '-')
        flag = true;
    else
        num = c - 48;
    while (std::isdigit(c = std::getchar()))
        num = num * 10 + c - 48;
    return (flag ? -1 : 1) * num;
}

struct stru
{
    long long w, h, v;
    bool operator<(const stru &t)
    {
        return v < t.v;
    }
} a[100001];

std::priority_queue<long long> q;
long long n, A, B, C;

bool cmp(const stru x, const stru y)
{
    return x.w > y.w;
}

int main(int argc, char ** argv)
{
    n = nextInt();
    A = nextInt();
    B = nextInt();
    C = nextInt();
    for (int i = 1; i <= n; i++)
    {
        a[i].h = nextInt();
        a[i].w = nextInt();
        a[i].h *= A;
        a[i].w *= B;
        a[i].v = a[i].h + a[i].w;
    }
    long long ans = 1;
    std::sort(a + 1, a + n + 1, cmp);
    for (int i = 1; i <= n; i++)
    {
        long long minh = a[i].h,
            minw = a[i].w;
        while (!q.empty())
            q.pop();
        q.push(a[i].v);
        for (int j = 1; j <= n; j++)
            if (i != j && a[j].h >= minh)
            {
                minw = std::min(minw, a[j].w);
                if (a[i].v > C + minh + minw)
                    break;
                while (!q.empty() && q.top() > C + minh + minw)
                    q.pop();
                if (a[j].v <= C + minh + minw)
                {
                    q.push(a[j].v);
                    ans = std::max(ans, (long long)q.size());
                }
            }
    }
    std::cout << ans << std::endl;
#ifdef __EDWARD_EDIT
    std::cin.get();
    std::cin.get();
#endif
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值