Codeforces Round #404 (Div. 2) C 二分查找
Codeforces Round #404 (Div. 2)
题意:对于 n and m (1 ≤ n, m ≤ 10^18) 找到
1) [n<= m] cout<<n;
2) [n>m]最小的 k => (k -m) * (k-m+1) >= (n-m)*2 成立
思路:二分搜索
#include <bits/stdc++.h>
#include <map>
using namespace std; #define LL long long
const long long INF = 1e10;
long long n, m, del, mix;
bool cal(long long a){
return a*(a+1) >= del;
} long long find(long long l, long long r){
while(l + 1 < r){
long long mid = (l +r) >> 1;
// cout<<(l+r)/2<<" "<<l<<" "<<r<<endl;
if(cal(mid)) r = mid;
else l = mid;
}
return l;
} int main(){
ios::sync_with_stdio(false); cin.tie(0);
// freopen("input2.txt", "r", stdin);
cin>>n>>m; if(n <= m) cout<<n<<endl;
if(n > m){
del = 2 * (n-m);
mix = find(0, 1e10);
while(!cal(mix)) mix++;
cout<<mix+m<<endl;
}
return 0;
}
Codeforces Round #404 (Div. 2) C 二分查找的更多相关文章
- Codeforces Round #377 (Div. 2)D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...
- Codeforces Round #404 (Div. 2) DE
昨晚玩游戏竟然不小心错过了CF..我是有多浪啊. 今天总算趁着下课时间补了,感觉最后两题还是挺有意思的,写个题解. D: 题目大意: 给出一个括号序列,问有多少个子序列 是k个'(' + k个')' ...
- Codeforces Round #404 (Div. 2) A,B,C,D,E 暴力,暴力,二分,范德蒙恒等式,树状数组+分块
题目链接:http://codeforces.com/contest/785 A. Anton and Polyhedrons time limit per test 2 seconds memory ...
- Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale 二分
C. Anton and Fairy Tale 题目连接: http://codeforces.com/contest/785/problem/C Description Anton likes to ...
- Codeforces Round #404 (Div. 2)A B C二分
A. Anton and Polyhedrons time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 【二分】Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale
当m>=n时,显然答案是n: 若m<n,在第m天之后,每天粮仓减少的量会形成等差数列,只需要二分到底在第几天,粮仓第一次下降到0即可. 若直接解不等式,可能会有误差,需要在答案旁边扫一下. ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- Codeforces Round #404 (Div. 2)A,B,C
A. Anton and Polyhedrons 题目链接:http://codeforces.com/contest/785/problem/A 智障水题 实现代码: #include<bit ...
- Codeforces Round #404 (Div. 2) D. Anton and School - 2 数学
D. Anton and School - 2 题目连接: http://codeforces.com/contest/785/problem/D Description As you probabl ...
随机推荐
- Flask从入门到放弃1:路由app.route()
Flask从入门到放弃1: Flask中的路由app.route(): 参考来源:http://python.jobbole.com/80956/ https://www.raspberrypi.or ...
- ReaderWriterLockSlim 类
今天在看Nop源码时,PluginManager中用到了ReaderWriterLockSlim类,于是简单做个笔记. ReaderWriterLockSlim 表示用于管理资源访问的锁定状态,可实现 ...
- Item 9 覆盖equals时总要覆盖hashCode
为什么覆盖equals时,总要覆盖hashCode? 原因是,根据Object规范: 如果两个对象根据equals(Object)方法比较是相等的,那么调用这两个对象中任意一个对象的hashCod ...
- bzoj3172 Ac自动机
根据fail树的性质 我们在建树的时候每建一个串就将他路径上的点全部加1表示这个串的后缀又出现了一次 然后从下到上把sum加起来就可以得到答案了 #include<cstdio> #inc ...
- Problem B. Harvest of Apples(杭电2018年多校+组合数+逆元+莫队)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6333 题目: 题意:求C(n,0)+C(n,1)+……+C(n,m)的值. 思路:由于t和n数值范围太 ...
- 什么是AMD规范
AMD规范全称是Asynchronous Module Definition,即异步模块加载机制.从它的规范描述页面看,AMD很短也很简单,但它却完整描述了模块的定义,依赖关系,引用关系以及加载机制. ...
- 使用JQGrid 问题汇总 不定时更新
jqgrid左下角的复杂搜索框显示为下拉框样式searchoptions: { value: ": 全部; 1: 在用; 2: 报废", sopt: ['eq'] } jqgrid ...
- perl 列出一个目录下的文件的大小
use strict; use warnings; use Cwd; my $dir = 'd:\\www'; chdir($dir); opendir DIR, $dir or die " ...
- 【swupdate文档 一】嵌入式系统的软件管理
嵌入式系统的软件管理 嵌入式系统变得越来越复杂, 它们的软件也反映了这种复杂性的增加. 为了支持新的特性和修复,很有必要让嵌入式系统上的软件 能够以绝对可靠的方式更新. 在基于linux的系统上,我们 ...
- sicily 1063. Who's the Boss
Time Limit: 1sec Memory Limit:32MB Description Several surveys indicate that the taller you are, ...