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. Linux FreeTDS的安装与配置

    Linux FreeTDS的安装与配置 一.简介 官方网站:http://www.freetds.org 版本:0.64 下载地址:http://ibiblio.org/pub/Linux/ALPHA ...

  2. vue 起步

    vue 官网 目前最火的前端框架当属Vue.js了,很多使用过vue的程序员这样评价它,“vue.js兼具angular.js和react.js的优点,并剔除了它们的缺点”.授予了这么高的评价的vue ...

  3. 03:git常见报错解决方法

    1.1 git常见报错解决方法 1.warning: LF will be replaced by CRLF in .idea/workspace.xml. 参考博客:https://www.cnbl ...

  4. python简说(二十一)开发接口

    一.flask举例 import flaskserver = flask.Flask(__name__)#新建一个服务,把当前这个python文件当做一个服务@server.route('/login ...

  5. BZOJ 1232 安慰奶牛题解

    题目传送门:BZOJ 1232 这是一个边权和点权结合在一起的题,但是因为要从当前点出发并回到原点,所以每个边都被经过了两次,节点至少被经过一次,所以我们将边权重新赋值,所以推出 那么遍历之后,并不是 ...

  6. Eclipse中手动清理项目缓存,

    用过Eclipse或MyEclipse的小伙伴肯定遇到过这种情况: 代码出错后,在前台访问出问题.然后把代码改好,已经检查不到错误,可是项目在前台访问还是有问题. 这个时候,可能就是Eclipse/M ...

  7. 20145308 《网络对抗》Web安全基础实践 学习总结

    20145308 <网络对抗> Web安全基础实践 学习总结 实验内容 本实践的目标理解常用网络攻击技术的基本原理.Webgoat实践下相关实验. 基础问题回答 (1)SQL注入攻击原理, ...

  8. JavaScript中this的用法 及 如何改变this的指向

    要懂得JavaScript中this的用法,首先需要知道,JavaScript中的作用域相关知识. var fun = function(){ var flag = 1; console.log(fl ...

  9. 基于快速排序思想partition查找第K大的数或者第K小的数。

    快速排序 下面是之前实现过的快速排序的代码. function quickSort(a,left,right){ if(left==right)return; let key=partition(a, ...

  10. 题解——洛谷P4767 [IOI2000]邮局(区间DP)

    这题是一道区间DP 思维难度主要集中在如何预处理距离上 由生活经验得,邮局放在中间显然最优 所以我们可以递推求出\( w[i][j] \)表示i,j之间放一个邮局得距离 然后设出状态转移方程 设\( ...