codeforces785C-bindary search,math
来源:互联网 发布:程序员开发工具网 编辑:程序博客网 时间:2024/06/07 03:51
首先居然跟出题人的小号分在一个room还被hack了无数次,不知道该不该开心呢?
题目大意:有一个谷仓容量为n,每天一早有m吨谷物运进来,但晚上有跟天数一样的老鼠出来吃,问第几天谷仓第一次没有谷物;
题目解析:一开始想着二分,还要注意边界不能爆LL,想一下最大的答案就是输入数据是1<<64,0吧,这个数据没有爆,可是没想到n<m的情况,其实这样直接输出n就ok了;
AC代码:
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespace std;const int maxn=200010;typedef long long ll;ll n,m;int main(){while(scanf("%lld%lld",&n,&m)!=EOF){ll l,r;int flag=0; r=1414213566; l=0; ll a;if(n-m>=0){flag=1;n-=m;}if(flag) {while(l<=r) { ll mid=(l+r)>>1; ll t; if(mid%2==0) { t=mid/2; t*=mid+1; } else { t=(mid+1)/2; t*=mid; } if(t<n) { l=mid+1; } else { r=mid-1; a=mid; } } } else a=n; if(flag==1) printf("%lld\n",a+m); else printf("%lld\n",a);}return 0;}
0 0
- codeforces785C-bindary search,math
- Codeforces785C (math,binary search)
- codeforces-729C-bindary search,math
- LightOJ-1062-bindary search
- LightOJ-1048-greedy+bindary search
- POJ-2104-线段树,bindary search
- Codeforces785C (二分)
- LeetCode 69 Sqrt(x)(Math、Binary Search)(*)
- LeetCode 50 Pow(x, n)(Math、Binary Search)(*)
- Math
- math
- Math
- Math
- Math
- Math
- math
- Math
- math
- matlab step函数跟踪斜坡信号及阶跃响应绘图
- 深入理解JavaScript中的立即执行函数(function(){.....})()
- Caffe-Miscoroft无训练日志解决方法
- Spring架构详解之Ioc容器的扩展点
- MPAndroidChart开源图表库之折线图
- codeforces785C-bindary search,math
- java虚拟机随手笔记(1)内存分配
- Linux—GPIO
- 特征工程
- Sublime Text 2 实用快捷键
- Search a 2D Matrix II
- Spring架构详解之动态代理的实现原理
- tomcat7.0.55配置单向和双向HTTPS连接(二)
- postgre删除数据表重复数据