Codeforecs 785C Anton and Fairy Tale 数学+二分
来源:互联网 发布:mac系统重装的网络加速 编辑:程序博客网 时间:2024/06/05 10:44
点击打开链接
题意:仓库最多放n件物品,第i天补充m件后 在拿i件,当仓库物品<=0结束,问第几天结束.n,m<=1e18
若m>=n 则第n天拿走n个后结束
若n>m
[1,m]天内补充min(i,m)=i,每天减少i 1~m天内,物品补充后都是满的
i=[m+1,ans]天起 (补充完后)每天还减小k,k=i-m
n=n-m(第m+1天的值)
设最后一天为k 则n<=1+2+..k 二分找到第一个满足的k即可
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N=2e5+20;ll n,m;int main(){while(cin>>n>>m){if(m>=n){//第n天拿走n个后结束 cout<<n<<endl;continue;}ll ans=m;ll cnt=0,l=0,r=2e9;n-=m;//m+1天开始时,n的值 while(l<=r) {ll mid=(l+r)>>1;ll val=mid*(mid+1)/2;if(n<=val){r=mid-1;cnt=mid;}elsel=mid+1;}cout<<ans+cnt<<endl;}return 0;}
0 0
- Codeforecs 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 785C Anton and Fairy Tale【二分答案+思维】
- codeforce 785 C.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
- C. Anton and Fairy Tale
- C. Anton and Fairy Tale
- C. Anton and Fairy Tale
- C. Anton and Fairy Tale
- C. Anton and Fairy Tale----思维+二分答案
- Codeforces #404 (Div. 2) C. Anton and Fairy Tale (二分
- 二分思路题Anton and Fairy Tale
- 消息认证码MAC-Message Authentication Code
- 大白话讲解Promise(一)
- js实现滑动门效果
- VisualStudio2015密钥
- [python3教程]第十二章.虚拟环境和程序集(VIRVUAL ENVIRONMENTS AND PACKAGES)
- Codeforecs 785C Anton and Fairy Tale 数学+二分
- Cython的安装
- 排序练习题
- 递归实现辗转相除以及筛法查找第n个素数
- 给网页添加图标
- 雅思考试是申请美国本科条件的试金石
- 文章标题
- DB2进行压缩的最佳实践
- vue学习笔记