大意: 给定$n$棵竹子, 每棵竹子初始$h_i$, 每天结束时长$a_i$, 共$m$天, 每天可以任选$k$棵竹子砍掉$p$, 若不足$p$则变为0, 求$m$天中竹子最大值的最小值

先二分答案转为判定最大值是否能<=$x$, 考虑如何进行判定.

直接贪心看的话很难办, 可能先砍当前较高的, 也可能砍最快的.

考虑将问题转化, 即初始高度均$x$, 每天结束时降低$a_i$, 可以选$k$棵拔高$p$, 要求每天竹子都不能降低到负数, 并且最后一天竹子高度$\ge h_i$

这样的话我们贪心, 每次选取最快降低到0的竹子一定是最优的, 因为拔高不会再产生浪费.

#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <string.h>
#include <queue>
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define hr putchar('\n')
#define pb push_back
#define mp make_pair
#define mid (l+r>>1)
#define lc (o<<1)
#define rc (lc|1) using namespace std;
typedef long long ll;
const int P = 1e9+7;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {
ll r=1%P;
for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;
return r;
}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;} const int N = 2e5+10;
int a[N], h[N], f[N], n, m, k, p;
struct _ {
ll day, id;
bool operator < (const _ & rhs) const {
return day>rhs.day;
}
}; priority_queue<_> q; bool check(ll x) {
memset(f, 0, sizeof f);
while (!q.empty()) q.pop();
REP(i,1,n) if (x-(ll)a[i]*m<h[i]) q.push({x/a[i],i});
REP(i,1,m) REP(j,1,k) {
if (q.empty()) return 1;
_ u = q.top();q.pop();
if (u.day<i) return 0;
if (x+(ll)p*++f[u.id]-(ll)m*a[u.id]<h[u.id]) {
q.push({(x+(ll)p*f[u.id])/a[u.id],u.id});
}
}
return q.empty();
} int main() {
scanf("%d%d%d%d", &n, &m, &k, &p);
REP(i,1,n) scanf("%d%d",h+i,a+i);
ll l=0, r=1e15, ans;
while (l<=r) check(mid)?ans=mid,r=mid-1:l=mid+1;
cout<<ans<<endl;
}

Mr. Kitayuta vs. Bamboos CodeForces - 505E (堆,二分答案)的更多相关文章

  1. Mr. Kitayuta vs. Bamboos

    Mr. Kitayuta vs. Bamboos 题目链接:http://codeforces.com/problemset/problem/505/E 参考:http://blog.csdn.net ...

  2. 「CF505E」 Mr. Kitayuta vs. Bamboos

    「CF505E」 Mr. Kitayuta vs. Bamboos 传送门 如果没有每轮只能进行 \(k\) 次修改的限制或者没有竹子长度必须大于 \(0\) 的限制那么直接贪心就完事了. 但是很遗憾 ...

  3. Codeforces 505E - Mr. Kitayuta vs. Bamboos(二分+堆)

    题面传送门 首先很显然的一点是,看到类似于"最大值最小"的字眼就考虑二分答案 \(x\)(这点我倒是想到了) 然鹅之后就不会做了/wq/wq/wq 注意到此题正着处理不太方便,故考 ...

  4. @codeforces - 506C@ Mr. Kitayuta vs. Bamboos

    目录 @description@ @solution@ @accepted code@ @details@ @description@ n 个竹子,第 i 个竹子初始高度 hi,在每天结束时将长高 a ...

  5. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  6. Codeforces 371C Hamburgers (二分答案)

    题目链接 Hamburgers 二分答案,贪心判断即可. #include <bits/stdc++.h> using namespace std; #define REP(i,n) fo ...

  7. CF505E Mr. Kitayuta vs. Bamboos

    cf luogu 要使得最高的柱子高度最小,考虑二分这个高度,那么剩下的就是要指定一个操作方案,使得最终每个柱子高度\(\le mid\) 因为有个柱子高度不会\(<0\)的限制,所以正着模拟不 ...

  8. 506C Mr. Kitayuta vs. Bamboos

    分析 代码 #include<bits/stdc++.h> using namespace std; #define int long long ],h[],now[],cnt[]; in ...

  9. CodeForces 505B Mr. Kitayuta's Colorful Graph

    Mr. Kitayuta's Colorful Graph Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

随机推荐

  1. linux服务器---squid缓存

    Squid缓存 代理服务器会在本地硬盘设置缓存,这样可以提高网络效率 1修改squid配置文件“/etc/squid/squid.conf”,参数“cache_dir_ufs”就是设置缓存目录的 [r ...

  2. Linux基础命令---findfs

    findfs 查找指定卷标或者UUID的文件系统对应的设备文件.findfs将搜索系统中的磁盘,寻找具有标签匹配标签或与UUID相等的文件系统.如果找到文件系统,文件系统的设备名称将打印在stdout ...

  3. AngularJs表单自动验证

    angular-auto-validate 地址:https://github.com/jonsamwell/angular-auto-validate 引用: <script src=&quo ...

  4. adb shell 命令详解,android, adb logcat

    http://www.miui.com/article-275-1.html http://noobjava.iteye.com/blog/1914348 adb shell 命令详解,android ...

  5. 20145318《网络对抗》注入shellcode及Return-to-libc

    20145318<网络对抗>注入shellcode及Return-to-libc 注入shellcode 知识点 注入shellcodeShellcode实际是一段代码(也可以是填充数据) ...

  6. 微信小程序——1、文件的认识

    主体文件的构成 微信小程序的主体由三个部分组成,需放在主目录中,名称也是固定的 app.js:微信小程序的主逻辑文件,主要用来注册小程序 app.json:微信小程序的主配置文件,对微信小程序进行全局 ...

  7. tensorflow reduction_indices理解

    在tensorflow的使用中,经常会使用tf.reduce_mean,tf.reduce_sum等函数,在函数中,有一个reduction_indices参数,表示函数的处理维度,直接上图,一目了然 ...

  8. NOIP Mayan游戏 - 搜索

    Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个7行5列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即方块必须放在最下面一行,或者放在其他方块之上.游戏通关是指在规定的步数内消除所有 ...

  9. ubuntu16.04下编译ceres-solver

    一.编译环境 ubuntu16.04 二.准备工作之安装必要的库 2.1安装cmake sudo apt-get install cmake 2.2 安装google-glog + gflags su ...

  10. swift设计模式学习 - 策略模式

    移动端访问不佳,请访问我的个人博客 设计模式学习的demo地址,欢迎大家学习交流 策略模式 策略模式定义了算法家族,分别封装起来,让它们之间可以相互替换,此模式让算法的变化,不会影响到使用算法的客户. ...