Codeforces 785C Anton and Fairy Tale (规律+二分查找)
来源:互联网 发布:优化环境工作方案 编辑:程序博客网 时间:2024/05/29 04:33
传送门
数据量过大, 暴力会超时, ;
找规律, 容易发现 当第m 天后 粮仓容量开始减少, 每天递增的数目是 以公差为1的等差数列, 前n项和为 n*(n+1)/2 所以
通俗的讲就是 二分查找 Sn>= n-m 即为结果;
#include <iostream>#include <stdio.h>#include <algorithm>#include <cmath>#include <cstring>#include <string>#include <queue>#include <stack>#include <set>#include <bitset>#include <vector>using namespace std;typedef long long ll;const double PI=acos(-1); const int INF=0x3f3f3f3f; const double esp=1e-6; const int maxn=1e18+2; const int MOD=1e9+7;#define mem(a,b) memset(a,b,sizeof(a))#define findx(x) lower_bound(b+1,b+1+bn,x)-bll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}int main(){ ll n,m;while(~scanf("%I64d %I64d",&n,&m)){ll ans;ll mid;ll le=0,ri=maxn;if(n<=m){ans=n;printf("%I64d\n",ans);continue;}while(le<ri){mid=(le+ri)/2;if(mid*(mid+1)/2>=n-m){ri=mid;}else le=mid+1;}printf("%I64d\n",le+m);}}//570441179141911871 511467058318039545
阅读全文
0 0
- Codeforces 785C Anton and Fairy Tale (规律+二分查找)
- Codeforces 785C Anton and Fairy Tale 找规律 二分
- codeforces 785C. Anton and Fairy Tale(二分)
- CodeForces 785C Anton and Fairy Tale【二分答案+思维】
- codeforces 785 C. Anton and Fairy Tale (数学 二分搜索)
- 【codeforces 785C】Anton and Fairy Tale
- Codeforces 785C-Anton and Fairy Tale
- CodeForces #785 c Anton and Fairy Tale
- Codeforces 785C Anton and Fairy Tale
- C. Anton and Fairy Tale-Codeforces Round #404 (Div. 2)-二分或者规律
- Codeforces #404 (Div. 2) C. Anton and Fairy Tale (二分
- Codeforecs 785C Anton and Fairy Tale 数学+二分
- codeforce 785 C.Anton and Fairy Tale(二分)
- codeforces Anton and Fairy Tale
- C. Anton and Fairy Tale
- C. Anton and Fairy Tale
- C. Anton and Fairy Tale
- C. Anton and Fairy Tale
- 不用加减乘除做加法
- 剑指Offer—30—连续子数组的最大和
- Cpage.js,一款轻盈的前端MVVM框架
- 【POJ
- 【计算机网络】第3章 数据链路层层 知识总结
- Codeforces 785C Anton and Fairy Tale (规律+二分查找)
- js 设置cookie
- iphone视频聊天代码实现
- Vue多元素过渡
- select、poll、epoll
- 一看就懂的数据库范式介绍(1NF,2NF,3NF,BC NF,4NF,5NF)
- Ch’s gift HDU
- 剑指offer-字符流中第一个不重复的字符
- GDB调试时候的问题