看到就会想到要二分这个x的值,那么接下来就考虑如何check()这个这个x值.
考虑使用一个优先队列,按照可以撑的时间排序,每次给可以撑的时间最少的点加上x的电,然后每当有可以超过k的,就直接移出队列,当队列为空时,便为成功,然后继续二分即可.

#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
//#include<bits/stdc++.h>
typedef long long ll;
#define INF 0x3f3f3f3f
ll gcd(ll a, ll b)
{return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {return a * b / (gcd(a, b));
}
#define PII pair<int,int>
using namespace std;
const int maxn = 2e6 + 10, mod = 1e9 + 7;
int qmi(int a, int k, int p)  //快速幂模板
{int res = 1;while (k){if (k & 1) res = (ll)res * a % p;k >>= 1;a = (ll)a * a % p;}return res;
}
template <class T>//快读
void read(T& x)
{char c;bool op = 0;while (c = getchar(), c < '0' || c > '9')if (c == '-')op = 1;x = c - '0';while (c = getchar(), c >= '0' && c <= '9')x = x * 10 + c - '0';if (op)x = -x;
}
template <class T>
void write(T x)
{if (x < 0)x = -x, putchar('-');if (x >= 10)write(x / 10);putchar('0' + x % 10);
}
///建图用的结构体
struct Edge
{int v, w, next;
}edge[maxn];
int tot = 0;
int head[maxn];
inline void Add_edge(int u, int v, int w)//建立邻接表
{edge[++tot].next = head[u];head[u] = tot;edge[tot].v = v;edge[tot].w = w;
}
///
ll a[maxn];
ll b[maxn];
ll n, k;
struct node {ll a, b, c;bool operator < (const node& x)const {if (c != x.c)return c > x.c;if (b != x.b)return b < x.b;return a > x.a;}
};
priority_queue<node> q;
bool check(ll y) {while (!q.empty()) q.pop();for (int i = 1; i <= n; i++)if (a[i] / b[i] < k)q.push({ a[i],b[i],a[i] / b[i] });if (q.empty()) {return true;}for (int i = 0; i < k; i++) {node t = q.top();q.pop();if (t.c < i)return false;if ((t.a + y) / t.b < k)q.push({ t.a + y,t.b,(t.a + y) / t.b });if (q.empty())return true;}return true;
}
int main() {read(n);read(k);for (int i = 1; i <= n; i++)read(a[i]);for (int i = 1; i <= n; i++)read(b[i]);ll l = 0, r = 2e12;ll ans = -1;while (l <= r) {ll mid = (l + r) / 2;if (check(mid))//找最小值,所以找到符合条件的应该让r=mid-1{ans = mid;r = mid - 1;}elsel = mid + 1;}cout << ans << endl;return 0;
}
/*
2 4
3 2
4 2
*/

很经典的二分用法,得需要牢记

CF1132D Stressful Training(优先队列+二分)相关推荐

  1. 【HihoCoder - 1269】 优化延迟 (优先队列+二分优化)

    题干: 小Ho编写了一个处理数据包的程序.程序的输入是一个包含N个数据包的序列.每个数据包根据其重要程度不同,具有不同的"延迟惩罚值".序列中的第i个数据包的"延迟惩罚值 ...

  2. 20181021模拟赛(暴力+暴力+优先队列二分)

    NOIP2016 提高组模拟赛 IzumiKonata 题目名Tetrix Tree Copier 输入文件名tetrix.in tree.in copier.in 输出文件名tetrix.out t ...

  3. Educational Codeforces Round 61 (Rated for Div. 2)(A、B、C、D、E、F)

    欢迎访问本菜鸡的独立博客:Codecho 比赛名称 Educational Codeforces Round 61 (Rated for Div. 2) 比赛链接 https://codeforces ...

  4. Codeforces 刷题记录(已停更)

    Codeforces 每日刷题记录 (已停更) 打'+'是一些有启发意义的题目,部分附上一句话题解,每日更新3题,大部分题目较水. Day ID Problem Tutorial Note 1 1 + ...

  5. 【Educational Codeforces Round 61 (Rated for Div. 2)】A.B.C.D.E.F.G

    前言 这场在最开始很顺利,A题6min1A,B题14min1A,但是由于C题过题人数太少一度认为这个C题很难,等有人过了才开始写最开始的想法,C题40min1A,过C之后发现F过的很多,去看提,发现和 ...

  6. Educational-Codeforces-Round-61-ABCDF题解

    A.Regular Bracket Sequence 题意 给你四种括号的数量,问是否存在一种组合方式让所有的括号匹配 思路 水题,怎么操作都可以. AC代码 #include <bits/st ...

  7. 了解splinternet:世界能否真正做到全球化?

    You may already be familiar with the term splinternet, a neologism made up of "split" and ...

  8. LA 4254 Processor 处理器 【二分 贪心 优先队列】

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21663 二分: 最大值最小的问题通过二分来求解.对处理器速度进行 ...

  9. CF802O-April Fools‘ Problem(hard)【wqs二分,优先队列】

    正题 题目链接:https://www.luogu.com.cn/problem/CF802O 题目大意 nnn天每条有aia_iai​和bib_ibi​. 每条可以花费aia_iai​准备至多一道题 ...

  10. LeetCode 1642. 可以到达的最远建筑(二分查找 / 优先队列贪心)

    文章目录 1. 题目 2. 解题 2.1 二分查找 2.2 优先队列+贪心 1. 题目 给你一个整数数组 heights ,表示建筑物的高度.另有一些砖块 bricks 和梯子 ladders . 你 ...

最新文章

  1. 设计模式之C#实现---- ProtoType
  2. lsync+rsync 实时同步(ubuntu16.04系统)
  3. 原始nginx.conf备份
  4. VTK:Utilities之SortDataArray
  5. 2016北理复试机试题
  6. BS7799, ISO/IEC 17799, ISO/IEC 27001容易混淆
  7. elasticsearch6.4.3实现搜索同义词
  8. 华为天才少年年薪201万,作息时间表曝光:所有的逆袭,都是蓄谋已久
  9. java aes iv_java AES加密解密
  10. Rust盒子小程序更新拍照查外挂功能,还能查Steam账户信息
  11. 与繁重的工作一起修行
  12. Domain Adaptation and Adaptive Information Fusion for Object Detection on Foggy Days
  13. 3DMAX在三维GIS建模中的应用与优化
  14. 3GPP TS 23501-g51 中英文对照 | 4.4.4 Location services
  15. CMMI有哪几个级别,每个级别有哪些其特征
  16. Cadence Allegro自动放置所有元件图文教程及视频演示
  17. 遥感ENVI5.1辐射定标以及大气矫正
  18. android studio添加繁体,Android (Android studio3.0.1)一篇可以实现app多语言的转换(简单操作)的教程-Go语言中文社区...
  19. 递归-数字旋转方阵问题
  20. C Primer Plus 练习 P85

热门文章

  1. 每天睡6小时和8小时的区别 看完再不敢熬夜了
  2. lisp 圆柱螺旋线_Visual LISP开发三维圆柱螺旋线程序
  3. Linux文件归档与压缩命令
  4. 饥荒 Don‘t Starve Together Mac游戏介绍
  5. 人文精神、人文教育与高等教育 徐梦秋
  6. 多拨软件测试,记一次折腾苏州移动宽带多拨的过程
  7. css3 3d 过 锯齿,css3 3d旋转 出现锯齿_html/css_WEB-ITnose
  8. ppt怎么压缩,ppt压缩的技巧分享
  9. python 任意时间段内的工作日计算(剔除法定节假日和周末)
  10. 数据库防火墙的性能和高可用性分析