hihoCoder #1269 : 优化延迟 【二分 + 优先队列】
来源:互联网 发布:阿里云ecs安装docker 编辑:程序博客网 时间:2024/04/20 20:24
题目链接:hihoCoder #1269 : 优化延迟
思路:二分然后维护一个
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#define PI acos(-1.0)#define CLR(a, b) memset(a, (b), sizeof(a))#define fi first#define se secondusing namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 1e5+10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;void getmax(int &a, int b) {a = max(a, b); }void getmin(int &a, int b) {a = min(a, b); }void add(LL &x, LL y) { x += y; x %= MOD; }priority_queue<int, vector<int>, less<int> > Q;int N; LL S;int a[MAXN];LL Count(int o){ LL ans = 0; int i = 1, j = 1; while(i <= N) { while(Q.size() < o && i <= N) { Q.push(a[i]), i++; } int v = Q.top(); Q.pop(); ans += 1LL * v * j; j++; } while(!Q.empty()) { int v = Q.top(); Q.pop(); ans += 1LL * v * j; j++; } return ans;}int main(){ while(scanf("%d%lld", &N, &S) != EOF) { for(int i = 1; i <= N; i++) scanf("%d", &a[i]); int l = 1, r = N; int ans = -1; while(r >= l) { int mid = (l + r) >> 1; if(Count(mid) <= S) { ans = mid; r = mid-1; } else l = mid+1; } cout << ans << endl; } return 0;}
0 0
- hihoCoder #1269 : 优化延迟 【二分 + 优先队列】
- hihoCoder--1469 优化延迟(二分+优先队列)
- HihoCoder 1269 优化延迟(二分、优先队列)
- hihocoder 136 #1269 优化延迟 二分+优先队列
- hiho 1269 优化延迟 二分 优先队列
- hihocoder1269 优化延迟(二分&优先队列)
- [Offer收割]编程练习赛1 hihocoder 1269 优化延迟 (二分+优先权队列)
- hiho一下 第136周 #1269 : 优化延迟 【二分+堆排序|优先队列】
- hihoCoder 1269 优化延迟
- hihoCoder#1269 : 优化延迟
- 【2016-北京赛区网络赛-I】枚举,贪心,优先队列,优化(导弹,hihocoder 1391)
- hihocoder #1613 : 墨水滴 bfs+优先队列
- dijstra+优先队列优化
- 优先队列优化 dijkstra
- Dijkstra(优先队列优化)
- Dijkstra优先队列优化
- uva1422 - Processor 二分+优先队列
- Processor(二分搜索,优先队列)
- android 6.0 SystemUI源码分析(5)-PowerUI介绍
- oracle外键约束表无法truncate
- HDOJ--5611(Baby Ming and phone number)(闰年)
- MySQL · 引擎特性 · InnoDB文件系统管理(二)
- MySQL · 引擎特性 · InnoDB Fulltext简介
- hihoCoder #1269 : 优化延迟 【二分 + 优先队列】
- python之正则表达式
- 使用pip安装指定版本的Python包
- 回答一个关于OSM技术栈的问题
- PyMOL习作
- Remove Nth Node From End of List
- 【Linux】VMware虚拟机中如何配置静态IP
- 20160305】的考试【补写一点东西
- 最小公倍数和最大公约数计算