CF985D Sand Fortress
思路:
很奇怪的结论题,不好想。参考了http://codeforces.com/blog/entry/59623
实现:
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const ll INF = 0x7f7f7f7f; 5 ll n, H; 6 bool check(ll m) 7 { 8 ll tmp = min(m, H); 9 return m * m - tmp * (tmp - 1) / 2 <= n; 10 } 11 ll solve(ll n, ll H) 12 { 13 ll l = 1, r = INF, ans = -1; 14 while (l <= r) 15 { 16 ll m = l + r >> 1; 17 if (check(m)) 18 { 19 ans = m; 20 l = m + 1; 21 } 22 else r = m - 1; 23 } 24 return ans; 25 } 26 int main() 27 { 28 while (cin >> n >> H) 29 { 30 ll k = solve(n, H); 31 ll t = min(k, H); 32 ll ans = 2 * k - 1 - t; 33 ll rem = n - (k * k - t * (t - 1) / 2); 34 ans += (rem + k - 1) / k; 35 cout << ans + 1 << endl; 36 } 37 return 0; 38 }
转载于:https://www.cnblogs.com/wangyiming/p/9077167.html
CF985D Sand Fortress相关推荐
- D - Sand Fortress CodeForces - 985D
D - Sand Fortress CodeForces - 985D number of spots you can occupy so that all the aforementioned co ...
- codeforces+contest+985D. Sand Fortress+思维
二分枚举长度 去算这一个点左边有多少个 D. Sand Fortress time limit per test 2 seconds memory limit per test 256 megabyt ...
- 【CodeForces - 985D】Sand Fortress (二分,贪心,思维构造,技巧,有坑)
题干: You are going to the beach with the idea to build the greatest sand castle ever in your head! Th ...
- Sand Fortress
思路 题意:对给定的n,H,把n划分为a1,a2,a3,-a1,a2,a3,-,要求首项a1≤Ha1≤H,相邻两项之差不大于1,而且最后一项必须是1.总个数要最少,输出这个最小的总个数. 我们先不想沙 ...
- Educational Codeforces Round 44 (Rated for Div. 2)
题目链接:https://codeforces.com/contest/985 'A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...
- A Grain of Sand 一粒沙子
William Blake/威廉.布莱克 To see a world in a grain of sand, And a heaven in a wild fllower, Ho ...
- 展望下一代语言:Fortress, Chapel or X10(转)
link:http://blog.csdn.net/phoenixsh 这三门语言是DARPA资助研究的HPCS系统(High Productivity Computer System),分别由SUN ...
- Governing sand(权值线段树/主席树)
链接:https://ac.nowcoder.com/acm/contest/887/C 来源:牛客网 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 65536K,其他语言13107 ...
- bzoj 3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MB Submit: 145 Solved: 119 ...
最新文章
- 后台的代理nginx部署方法
- irobot擦地机器人故障_懒人必备神器,电动高频擦地,科沃斯地宝T8 AIVI扫地机器人...
- JS 之 innerHTML
- Android的Handler,Looper源码剖析
- Java 基础——数组解析
- linux vi编辑器 Ctrl s,Linux命令-----vi/vim编辑器
- 笔记:Microservices for Java Developers
- vs2008 sp1补丁安装到最后一点点的时候,就无法安装下去了 解决方法
- 服务器与虚拟技术,云服务器与虚拟化服务器的区别
- 尔雅大学计算机基础知识点,超星尔雅_大学计算机基础_章节测试答案
- 非科班无实习如何入职腾讯?后台开发岗个人校招学习路线分享!
- 抖音文案、声音、设计、视频、图片素材网站
- 互联网架构师必备技能(使用markdown编写)
- python中fn是什么意思_Python fn
- python一行输入多个值用空格隔开_Python 实现一行输入多个数字(用空格隔开)
- 非root用户安装命令
- 伯禹公益AI《动手学深度学习PyTorch版》Task 07 学习笔记
- 【循环搜寻法(使用卫兵)】
- Oracle练习题(九)
- Oracle 12cR1 RAC 在VMware Workstation上安装(上)—OS环境配置