Codeforces 985 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的更多相关文章
- codeforces 985 D. Sand Fortress(二分+思维)
Sand Fortress time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces 985 最短水桶分配 沙堆构造 贪心单调对列
A B /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a, ...
- CodeForces 985D Sand Fortress
Description You are going to the beach with the idea to build the greatest sand castle ever in your ...
- CF985D Sand Fortress
思路: 很奇怪的结论题,不好想.参考了http://codeforces.com/blog/entry/59623 实现: #include <bits/stdc++.h> using n ...
- Codeforces 985 F - Isomorphic Strings
F - Isomorphic Strings 思路:字符串hash 对于每一个字母单独hash 对于一段区间,求出每个字母的hash值,然后排序,如果能匹配上,就说明在这段区间存在字母间的一一映射 代 ...
- Codeforces 985 E - Pencils and Boxes
E - Pencils and Boxes 思路: dp 先排个序,放进一个袋子里的显然是一段区间 定义状态:pos[i]表示小于等于i的可以作为(放进一个袋子里的)一段区间起点的离i最近的位置 显然 ...
- 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 ...
- Educational Codeforces Round 44#985DSand Fortress+二分
传送门:送你去985D: 题意: 你有n袋沙包,在第一个沙包高度不超过H的条件下,满足相邻两个沙包高度差小于等于1的条件下(注意最小一定可以为0),求最少的沙包堆数: 思路: 画成图来说,有两种可能, ...
- Educational Codeforces Round 44 (Rated for Div. 2)
题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...
随机推荐
- UnicodeEncodeError: 'utf-8' codec can't encode character '\udce4' in position 1: surrogates not allowed根本解决方法
下午开发新改的代码在print路径时出现上述问题,如下: Traceback (most recent call last): File "./update.py", line 6 ...
- oracle 12c AUTO_SAMPLE_SIZE动态采用工作机制
The ESTIMATE_PERCENT parameter in DBMS_STATS.GATHER_*_STATS procedures controls the percentage of ro ...
- protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 2, class-id=60, method-id=80)
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.c ...
- 【题解】Luogu SP8791 DYNALCA - Dynamic LCA
原题传送门 这题用Link-Cut-Tree解决,Link-Cut-Tree详解 这道题的难点就在如何求LCA: 我们珂以先对其中一个点进行access操作,然后对另一个点进行access操作,因为L ...
- win7记事本txt图标显示异常解决方法
链接:https://zhidao.baidu.com/question/2076205353435701108.html ...
- Oracle使用——oracle用户相关操作
前提 以dba角色登录数据库(普通用户没有操作权限):sqlplus / as sysdba 具体操作 创建用户 创建用户 使用默认表空间创建用户 create user xzgxh identifi ...
- Linux使用——Linux命令——Linux 系统基本命令使用记录
查看系统版本信息 查看系统版本:cat /proc/version 查看cpu相关信息,包括型号.主频.内核信息:cat /proc/cpuinfo 快速了解CPU使用情况:free -h 解压文件 ...
- Nginx 安装及配置
目录 概念 安装 配置文件 主要文件位置 注意点 Nginx运行 FAQ Q1:nginx: [error] open() "/usr/local/var/run/nginx.pid&quo ...
- 【问题解决:时区】连接MySQL时错误The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
问题描述: MySQL升级到8.0.11之后连接数据库报错: Your login attempt was not successful, try again. Reason: Could not g ...
- LOJ 6485 LJJ学多项式
前言 蒟蒻代码惨遭卡常,根本跑不过 前置芝士--单位根反演 单位根有这样的性质: \[ \frac{1}{n}\sum_{i=0}^{n-1}\omega_{n}^{ki}=\left[n|k\rig ...