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 二分查找的更多相关文章

  1. Codeforces Round #377 (Div. 2)D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...

  2. Codeforces Round #404 (Div. 2) DE

    昨晚玩游戏竟然不小心错过了CF..我是有多浪啊. 今天总算趁着下课时间补了,感觉最后两题还是挺有意思的,写个题解. D: 题目大意: 给出一个括号序列,问有多少个子序列 是k个'(' + k个')' ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 【二分】Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale

    当m>=n时,显然答案是n: 若m<n,在第m天之后,每天粮仓减少的量会形成等差数列,只需要二分到底在第几天,粮仓第一次下降到0即可. 若直接解不等式,可能会有误差,需要在答案旁边扫一下. ...

  7. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

  8. Codeforces Round #404 (Div. 2)A,B,C

    A. Anton and Polyhedrons 题目链接:http://codeforces.com/contest/785/problem/A 智障水题 实现代码: #include<bit ...

  9. 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 ...

随机推荐

  1. 【HNOI】 lct tree-dp

    [题目描述]给定2-3颗树,每个边的边权为1,解决以下独立的问题. 现在通过连接若干遍使得图为连通图,并且Σdis(x,y)最大,x,y只算一次. 每个点为黑点或者白点,现在需要删除一些边,使得图中的 ...

  2. device tree 負值 property 寫法

    倘若你要設定 負值的property, 可能需要括符才會 build 過. 正確 decidegc = <(-10)>; 錯誤 decidegc = <-10>;

  3. python基础===python实现截图

    python实现全屏截图: from PIL import ImageGrab im = ImageGrab.grab() im.save('F:\\12.png')

  4. 解决sql server中批处理过程中“'CREATE/ALTER PROCEDURE 必须是查询批次中的第一个语句”

    在批处理中加字段或表或视图或存储过程是否存在的判断 -----------------------------------------line----------------------------- ...

  5. 微信小程序获取输入框(input)内容

    微信小程序---获取输入框(input)内容 wxml <input placeholder="请输入手机号码" maxlength="11" type= ...

  6. Linux操作系统中内存buffer和cache的区别--从free命令说起(转)

    原文链接:http://os.51cto.com/art/200709/56603.htm 我们一开始,先从Free命令说起. Free free 命令相对于top 提供了更简洁的查看系统内存使用情况 ...

  7. Linux 日志系统及分析

    简介 在Centos 7.x / RHEL 7.x 的版本,系统日志是由一个名为 rsyslog的服务管理的,默认的日志守护进程为 rsyslog , rsyslog 是 syslog 的升级版本,默 ...

  8. 关于自适应屏幕,设置子元素浮动,父div不能包裹子div,子元素中内容溢出的问题。

    设置HTML适应不同分辨率的屏幕. 需求结构如下: HTML结构代码如下(只是其中一条): <body> <div class="content">< ...

  9. Spiral Matrix I&&II

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  10. 使用dpkg命令卸载已经安装的软件包

    如何在Ubuntu中使用dpkg命令卸载软件 http://jingyan.baidu.com/article/f54ae2fc2724a71e92b849c4.html sudo dpkg -i x ...