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. unity ugui缩放+移动

    本文仅仅记录自己在工作中踩到的ugui的坑.并讲述如何填的坑. 干货罗列在前,不愿意看的,拿东西走人,自己研究: RectTransform m_Rect m_Rect.localPosition m ...

  2. jQuery取值的一些奇奇怪怪的操作

    语法解释:1. $("#select_id").change(function(){//code...});   //为Select添加事件,当选择其中一项时触发2. var ch ...

  3. hdu 1162 Eddy's picture(最小生成树算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...

  4. 我的spring boot,杨帆、起航!

    快速新建一个spring boot工程可以去http://start.spring.io/这个网址,配置完后会自动下载一个工程的压缩包,解压后导入相关ide工具即可使用. 工程中会自带一个class启 ...

  5. Spring Boot:定制自己的starter

    在学习Spring Boot的过程中,接触最多的就是starter.可以认为starter是一种服务——使得使用某个功能的开发者不需要关注各种依赖库的处理,不需要具体的配置信息,由Spring Boo ...

  6. Python3 高阶函数

    高阶函数 (满足其一就是:(1)一个函数名作为另一个函数的形参:(2)返回值包含函数名;不修改函数的调用方式) 1.一个函数名作为另一个函数的形参 输出结果: 2.返回值包含函数名;不修改函数的 输出 ...

  7. JAVA常见的集合类

    关系的介绍: Set(集):集合中的元素不按特定方式排序,并且没有重复对象.他的有些实现类能对集合中的对象按特定方式排序. List(列表):集合中的元素按索引位置排序,可以有重复对象,允许按照对象在 ...

  8. django wsgi nginx 配置

    """ WSGI config for HelloWorld project. It exposes the WSGI callable as a module-leve ...

  9. System.getProperty方法中输出路径的方法

    package codegenerator;/** *@author Eilen *@date 2017年9月27日---下午3:15:09 *@描述: *@answer */public class ...

  10. dos命令连接mysql并且查看编码方式

    打开cmd: 输入:mysql -hlocalhost -uroot -p 然后: show variables like 'char%';