CF985D Sand Fortress
思路:
很奇怪的结论题,不好想。参考了http://codeforces.com/blog/entry/59623
实现:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 0x7f7f7f7f;
ll n, H;
bool check(ll m)
{
ll tmp = min(m, H);
return m * m - tmp * (tmp - ) / <= n;
}
ll solve(ll n, ll H)
{
ll l = , r = INF, ans = -;
while (l <= r)
{
ll m = l + r >> ;
if (check(m))
{
ans = m;
l = m + ;
}
else r = m - ;
}
return ans;
}
int main()
{
while (cin >> n >> H)
{
ll k = solve(n, H);
ll t = min(k, H);
ll ans = * k - - t;
ll rem = n - (k * k - t * (t - ) / );
ans += (rem + k - ) / k;
cout << ans + << endl;
}
return ;
}
CF985D Sand Fortress的更多相关文章
- Codeforces 985 D - Sand Fortress
D - Sand Fortress 思路: 二分 有以下两种构造, 分别二分取个最小. 代码: #include<bits/stdc++.h> using namespace std; # ...
- codeforces 985 D. Sand Fortress(二分+思维)
Sand Fortress time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- CodeForces 985D Sand Fortress
Description You are going to the beach with the idea to build the greatest sand castle ever in your ...
- Educational Codeforces Round 44 (Rated for Div. 2)
题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...
- Codeforces 985 最短水桶分配 沙堆构造 贪心单调对列
A B /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a, ...
- bzoj 3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MB Description 约翰用沙子建了一座城堡.正 ...
- BZOJ3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 22 Solved: 17[Sub ...
- 3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 37 Solved: 32[Sub ...
- gym 101081 E. Polish Fortress 几何
E. Polish Fortress time limit per test 2.0 s memory limit per test 256 MB input standard input outpu ...
随机推荐
- JVM对象存活判断方法
一.GC主要针对什么区域 1. 程序计数器.虚拟机栈.本地方法栈,3个部分随线程而生死.每个栈桢分配多少内存基本上是在类结构确定下来时就已确定,大体上可认为是 编译期可知. 2. 而 堆 和 方法区 ...
- NEU 1683: H-Index
题目描述 Given an array of citations (each citation is a non-negative integer) of a researcher, write a ...
- 大整数分解质因数(Pollard rho算法)
#include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> ...
- 命令行唤起xcode模拟器
1.IOS模拟器列表获取命令 xcrun instruments -s 2.IOS启动模拟器命令 xcrun instruments -w "iPhone 8 (12.1)"
- linux子系统的初始化_subsys_initcall()
http://my.oschina.net/u/572632/blog/305492#OSC_h1_3
- hihocoder 1015 KMP(找多个位置的 【*模板】)
#1015 : KMP算法 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在 ...
- 以太坊EVM在安全性方面的考虑
以太坊上用户编写的合约是不可控的,要保证这些合约能够正确执行并且不会影响区块链的稳定,虚拟机需要做安全方面的考虑. 1 在程序执行过程中采取的每个计算步骤都必须提前支付费用, 从而防止DoS攻击.先消 ...
- 原:maven+springMVC+mybatis+junit详细搭建过程
阅读目录 1. 工程目录结构整理清楚 2. 引入依赖包 3. 配置数据库连接属性 4. 配置spring配置文件 5. java代码编写(model,dao,service层代码) 6. m ...
- nodejs supvisor模块
在测试nodejs程序的时候,每次都需要在控制台编译,非常的麻烦.supervisor是一款无需重复手动编译,自动后台监听文件变化来自动编译,并且不需要在项目内require,使用非常的方便. 使用方 ...
- Quartz 2D(常用API函数、绘制图形、点线模式)
Quzrtz 2D 绘图的核心 API 是 CGContextRef ,它专门用于绘制各种图形. 绘制图形关键是两步: 1.获取 CGContextRef ; 2.调用 CGContextRef 的方 ...