Codeforces 1132D(二分模拟)
要点
- 二分显然,关键在于怎么判断
- 题解方法:开k个队列代表每个时间有哪些电脑会挂掉,这部分O(n)预处理一下,之后扫一遍时间,每个时间点贪心选取最靠前的会挂的电脑未雨绸缪给它充电,然后看看充电以后要不要换队列,这样就把n * k的变成了n + k的
const int maxn = 2e5 + 5;
int n;
ll k;
ll a[maxn], b[maxn], cur[maxn];
queue<int> Q[maxn];
bool ok(ll mid) {
rep(i, 0, k) while(Q[i].size()) Q[i].pop();
rep(i, 1, n) {
cur[i] = a[i];
ll t = cur[i] / b[i] + 1;
if (t <= k) Q[t].push(i);
cur[i] %= b[i];
}
int p = 0;
rep(i, 0, k) {
while (p <= k && Q[p].empty()) p++;
if (p > k) return true;
if (p <= i) return false;
int t = Q[p].front();
if (cur[t] + mid < b[t]) {
cur[t] += mid;
continue;
}
Q[p].pop();
ll d = (cur[t] + mid) / b[t];
if (p + d <= k) Q[p + d].push(t), cur[t] = (cur[t] + mid) % b[t];
}
return true;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> k;
k--;
rep(i, 1, n) cin >> a[i];
rep(i, 1, n) cin >> b[i];
ll l = 0, r = INF, ans = -1;
while (l <= r) {
ll mid = (l + r) >> 1;
if (ok(mid)) {
r = mid - 1;
ans = mid;
} else l = mid + 1;
}
cout << ans << endl;
return 0;
}
Codeforces 1132D(二分模拟)的更多相关文章
- Codeforces 1132D(二分答案+堆)
题面 传送门 分析 二分答案,考虑如何判定 可以用贪心的方法,每次找最快没电的电脑,在没电前1单位时间给它充电 正确性显然 实现上可以维护一个堆,存储每个电脑电用完的时刻,每次从堆顶取出最小的一个给它 ...
- Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟
A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces 1132D - Stressful Training - [二分+贪心+优先队列]
题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有 $n$ 个学生,他们的电脑有初始电量 $a[1 \sim n]$,他们的电脑每分钟会耗 ...
- Codeforces 1011C Fly(二分+模拟)
题意: 是有n个星球,1代表地球,然后输入一个m表示火箭的重量,然后输入了两组n个数,第一组表示在每个星球起飞时消耗一吨燃料的质量数,a[i]就表示每a[i]吨就要消耗1吨燃料,第二组就表示在每个星球 ...
- Codeforces 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
- codeforces 591B Rebranding (模拟)
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- CodeForces - 363D --二分和贪心
题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...
- 【Codeforces 1132D】Stressful Training
Codeforces 1132 D 题意:给\(n\)个电脑的电量和耗电速度,你可以买一个充电器,它的充电速度是每秒\(v\)单位,\(v\)你自己定.问最小的\(v\)能使得在\(k\)秒内每秒给某 ...
随机推荐
- POJ 1088 滑雪 ( DFS+动态规划思想 )
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 79519 Accepted: 29581 Description ...
- LightOJ1138 —— 阶乘末尾0、质因子分解
题目链接:https://vjudge.net/problem/LightOJ-1138 1138 - Trailing Zeroes (III) PDF (English) Statistic ...
- P2759 奇怪的函数
题目描述 使得 x^x 达到或超过 n 位数字的最小正整数 x 是多少? 输入输出格式 输入格式: 一个正整数 n 输出格式: 使得 x^x 达到 n 位数字的最小正整数 x 输入输出样例 输入样例# ...
- HTTP Status 500 - Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
如果在service类上面没有添加注解,出现异常 @Transactional
- C++基础--完善Socket C/S ,实现客户端,服务器端断开重连
// WindowsSocketServer.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"#include <iostream> ...
- MTK LCM帧率设置公式
clk=(width + W total porch)x(height + H total porch)x (6<18bit>或者x8<24bit>)x fps/ lane n ...
- HDU1171(01背包均分问题)
Big Event in HDU Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- 【旧文章搬运】Win7可变对象头结构之InfoMask解析
原文发表于百度空间,2010-08-11========================================================================== 对Wind ...
- Oauth2的遇坑一点提示(Spring Security Oauth2 / Cloud)
1)使用@EnableOAuth2Sso的网页客户端,登录是成功的可是总是像没成功一样. 提示错误:没有 症结:context-path没设置,或者设置为/(ROOT) 参考资料:https://sp ...
- mfc画波形函数
void CMyPicoTestDlg::DrawWave(CDC *pDC,CRect &rectPicture) { float fDeltaX; float fDeltaY; int n ...