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. CRC、MD5和SHA1的区别?

    什么是CRC校验?CRC即循环冗余校验码:是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定.循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式计算,并将 ...

  2. java.lang.NoClassDefFoundError: org/apache/curator/RetryPolicy解决方法

    今天集成es-job到公司的框架时,启动时出现上述错误 java.lang.NoClassDefFoundError: org/apache/curator/RetryPolicy at storm. ...

  3. ssh-keygen 不是内部或外部命令

    如何处理呢? 1.找到Git/usr/bin目录下的ssh-keygen.exe(如果找不到,可以在计算机全局搜索) 2.属性-->高级系统设置-->环境变量-->系统变量,找到Pa ...

  4. Angular 父子组件传值

    Angular 父子组件传值 @Input  @Output  @ViewChild 新建一个头部组件 newsheader 在主组件引用 news 组件,在news组件添加 newsheader 组 ...

  5. jQuery 表单内容的获取

    var formData = $('#myform').serialize()

  6. VS2012创建ATL工程及使用MFC测试COM组件

    一.创建ATL工程 1.创建ATL项目,取名为ATLMyCom 2.在ATL项目向导中,勾选[支持MFC](利用MFC测试用).[支持 COM+ 1.0],其余的选项默认,点击完成. 3.右键工程名称 ...

  7. 【Python48--魔法方法:迭代器&生成器】

    一.迭代器 1.iter() __iter__() 2.next() __next__() 二.用while语句实现for语句相同的功能 for each in range(5): print(eac ...

  8. Linux下调整ext3分区大小【转】

    本文转载自:https://blog.csdn.net/cruise_h/article/details/22403529 本文讨论如何再不丢失数据的情况下调整已有ext3分区的大小,包括: 压缩已有 ...

  9. selinux权限问题【转】

    本文转载自:https://blog.csdn.net/u011386173/article/details/83339770 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...

  10. matlab做聚类分析

    说明:如果是要用matlab做kmeans聚类分析,直接使用函数kmeans即可.使用方法:kmeans(输入矩阵,分类个数k). 转载一: MATLAB提供了两种方法进行聚类分析: 1.利用 clu ...