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必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...
随机推荐
- Kali系列之multi/handler(渗透win7)
环境 靶机 192.168.137.133 kali 192.168.137.135 步骤+ 生成后门 msfvenom -p windows/meterpreter/reverse_tcp LHOS ...
- python简说(十五)MD5加密
def my_md5(s): news = str(s).encode() m = hashlib.md5(news) return m.hexdigest()
- Codeforces 837D Round Subset - 动态规划 - 数论
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n ...
- C# 文件与二进制之间的转换
/// <summary> /// 工具类:文件与二进制流间的转换 /// </summary> public class FileBinaryConvertHelper { ...
- main.dart
import 'package:flutter/material.dart'; import 'package:flysnow_2ull/index/index.dart'; // 导入index.d ...
- openwrt源码下的feeds.conf.default有何作用?
答: 可以往openwrt下添加一些最新的软件包,这样make menuconfig后就可以发现很多软件包了. 该文件中的内容格式如下例: src-git packages https://git.l ...
- linux内核中宏container_of是干什么的?
Linux Kernel Version 4.14 1. container_of是干什么的? 已知一个结构体中某个成员的首指针,那么就可以通过宏container_of来获得此结构体的首指针 2 先 ...
- linux基础之条件测试
关键词: 数值测试 字符串测试 文件测试 测试命令有三种方式: test EXPRESSION [ EXPRESSION ] [[ EXPRESSION ]] 注意:EXPRESSION前后有空白字符 ...
- resure挽救笔记本系统和一些相关的操作记录
使用fedora23很久了, 但是感觉不是很流畅, 出现了一些不太稳定的体验, 所以想改到centos7. 因为centos7的很多东西 跟 fedora23 很相近了. 所以应该是无缝过渡 是选择3 ...
- Mysql的timestamp字段默认值设置问题
参考: https://www.cnblogs.com/mxwz/p/7520309.html https://www.jb51.net/article/50878.htm https://blog. ...