首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >洛谷P4165 [SCOI2007]组队(排序 堆)

洛谷P4165 [SCOI2007]组队(排序 堆)

作者头像
attack
发布2018-12-24 13:27:06
4200
发布2018-12-24 13:27:06
举报

题意

题目链接

Sol

跟我一起大喊:n方过百万,暴力踩标算!

一个很显然的思路是枚举\(H, S\)的最小值算,复杂度\(O(n^3)\)

我们可以把式子整理一下,变成

\[A H_i + B S_i \leqslant C + AminH + BminS\]

首先按\(H\)排序

考虑去从大到小枚举\(AminH\),同时用个vector \(n^2\)维护\(S\)序列(直接\(lowerbound + insert\))

再从大到小枚举\(BminS\),同时用堆维护\(AH_i + B_i\),当堆顶不满足条件的时候直接弹掉即可,用堆内元素更新答案

没错在BZOJ上被卡了

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define Pair pair<int, int> 
#define MP make_pair
#define fi first 
#define se second 
using namespace std;
const int MAXN = 5001, mod = 1e9 + 7;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, A, B, C, th[MAXN], ts[MAXN];
struct Node {
    int h, s, id;
    bool operator < (const Node &rhs) const {
        return h < rhs.h;
    }
}a[MAXN];
signed main() {
    N = read(); A = read(); B = read(); C = read();
    for(int i = 1; i <= N; i++) th[i] = a[i].h = read(), a[i].s = read();
    sort(th + 1, th + N + 1);
    sort(a + 1, a + N + 1); 
    int ans = 0;
    vector<Pair> v;
    for(int i = N; i >= 1; i--) {
        Pair now = MP(B * a[i].s, A * a[i].h + B * a[i].s);
        v.insert(lower_bound(v.begin(), v.end(), now), now);
        //__gnu_pbds::priority_queue<int> q; 
        priority_queue<int> q;
        int r = v.size() - 1; 
        for(int j = r; j >= 0; j--) {
            q.push(v[j].se);
            while(!q.empty() && q.top() > C + A * th[i] + v[j].fi) q.pop();
            ans = max(ans, (int)q.size());
        }
    }
    cout << ans;
    return 0;
}
/*
*/
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-12-03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题意
  • Sol
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档