D - Sand Fortress

思路:

二分

有以下两种构造,

分别二分取个最小。

代码:

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head
ULL n, h;
bool check(ULL t) {
ULL res;
if(t >= h) res = (+t)*t/ + t*(t-)/ - h*(h-)/;
else res = (+t)*t/;
if(res >= n) return true;
else return false;
}
bool Check(ULL t) {
ULL res;
if(t >= h) res = (+t)*t - h*(h-)/;
else res = (+t)*t/;
if(res >= n) return true;
else return false;
}
int main() {
scanf("%llu%llu", &n, &h);
ULL l = , r = 2e9, m = (l+r) >> ;
while(l < r) {
if(check(m)) r = m;
else l = m+;
m = (l+r) >> ;
}
ULL ans;
if(m >= h) ans = *m - h;
else ans = m;
l = , r = 2e9, m = (l+r) >> ;
while(l < r) {
if(Check(m)) r = m;
else l = m+;
m = (l+r) >> ;
}
if(m >= h) ans = min(ans, *m - h + );
else ans = min(ans, m);
printf("%llu\n", ans);
return ;
}

Codeforces 985 D - Sand Fortress的更多相关文章

  1. codeforces 985 D. Sand Fortress(二分+思维)

    Sand Fortress time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. Codeforces 985 最短水桶分配 沙堆构造 贪心单调对列

    A B /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a, ...

  3. CodeForces 985D Sand Fortress

    Description You are going to the beach with the idea to build the greatest sand castle ever in your ...

  4. CF985D Sand Fortress

    思路: 很奇怪的结论题,不好想.参考了http://codeforces.com/blog/entry/59623 实现: #include <bits/stdc++.h> using n ...

  5. Codeforces 985 F - Isomorphic Strings

    F - Isomorphic Strings 思路:字符串hash 对于每一个字母单独hash 对于一段区间,求出每个字母的hash值,然后排序,如果能匹配上,就说明在这段区间存在字母间的一一映射 代 ...

  6. Codeforces 985 E - Pencils and Boxes

    E - Pencils and Boxes 思路: dp 先排个序,放进一个袋子里的显然是一段区间 定义状态:pos[i]表示小于等于i的可以作为(放进一个袋子里的)一段区间起点的离i最近的位置 显然 ...

  7. codeforces 985 E. Pencils and Boxes (dp 树状数组)

    E. Pencils and Boxes time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. Educational Codeforces Round 44#985DSand Fortress+二分

    传送门:送你去985D: 题意: 你有n袋沙包,在第一个沙包高度不超过H的条件下,满足相邻两个沙包高度差小于等于1的条件下(注意最小一定可以为0),求最少的沙包堆数: 思路: 画成图来说,有两种可能, ...

  9. Educational Codeforces Round 44 (Rated for Div. 2)

    题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...

随机推荐

  1. centos6编译安装mysql5.5

    常规编译安装:./configure;make;make install centos 6.5,安装mysql 5.5.54,所需安装包cmake-2.8.8.tar.gz.mysql-5.5.54. ...

  2. word2010自定义的多级列表编号变成黑块的解决办法

    首先,看图说话 是的,当我保存Word再打开之后,我辛辛苦苦(没错,小白有罪,调来调去真辛苦)搞得多级列表编号变成了黑块,默默无言,只有泪千行,还好有万能的Google. 解决办法: 将光标移到黑块的 ...

  3. fjwc2019 D1T2 原样输出(后缀自动机+dp)

    #179. 「2019冬令营提高组」原样输出 暴力对每个串建后缀自动机,然后暴力枚举每个自动机的子串.可以拿到部分分. 然鹅我们可以把每个后缀自动机连起来. 我们知道,后缀自动机是用最少的点(空间)表 ...

  4. mysql 5.7多源复制(用于生产库多主库合并到一个查询从库)

    目前我们使用的是主从+分库分表的系统架构,主库有N个分库,从库为多个slave做负载均衡,所以数据库端的架构是下面这样的: 因为差不多有一年半没有专门搞技术为主了,顺带回顾下. 这就涉及到多个主库数据 ...

  5. 选择排序法、冒泡排序法、插入排序法、系统提供的底层sort方法排序之毫秒级比较

    我的代码: package PlaneGame;/** * 选择排序法.冒泡排序法.插入排序法.系统提供的底层sort方法排序之毫秒级比较 * @author Administrator */impo ...

  6. Linux普通用户不能使用TAB键、上下键

    出发点 今天安装使用kail linux的时候发现tab键命令不能补全, 结合ubuntu, 因默认ubuntu创建的普通帐号,默认shell为/bin/sh,而这不支持tab等键的,所以将「指定用户 ...

  7. windows下常用的几个批处理脚本

    1.windows下对比两个文件内容,有差异则执行一个任务: 适用场景:比如你的数据库备份结果的日志每天会形成一个文件,如下图,你可以通过此脚本检测到文件的变化,并执行发送告警邮件通知你数据库备份异常 ...

  8. ldap集成jenkins

    jenkins版本:2.5.3,ldap插件:1.15 jenkins ldap支持需要安装ldap plugin,强烈建议插件安装版本为1.15及以上(支持ldap 配置测试) 安装插件: 系统管理 ...

  9. 【Python043-魔法方法:算术方法2】

    一. 反运算符 当对应的操作数不支持调用时,反运算数被调用(参考资料Lhttps://fishc.com.cn/thread-48793-1-1.html ) 1.对象(a+b)相加,如果对象a有__ ...

  10. 鼠标滑轮事件QWheelEvent

    一般鼠标滑轮事件会发出信号,参数是QWheelEvent,只需要新建槽函数,QWheelEvent作为参数. void myMouseWheelEvent(QWheelEvent* even) {)/ ...