Codeforces 785C Anton and Fairy Tale
来源:互联网 发布:淘宝p图教程 编辑:程序博客网 时间:2024/06/06 00:44
题意:仓库里最多能放maxn个粮食,每天往仓库里添加k个粮食,如果添加k个粮食后超过了仓库的容量,那么就把超出的部分扔掉,也就是说仓库满了之后就不能再添加粮食了。同时每天都有鸟去偷吃粮食,第一天一只鸟,第二天两只鸟,第三天三只鸟...依此类推,每只鸟只能吃一个粮食,求仓库在第几天第一次为空
解题思路:二分法,可以直接推公式。如果k>=maxn,那么前maxn天都能补满仓库,第maxn天有maxn只鸟来吃,仓库就空了,所以这种情况就是在maxn天仓库第一次为空。如果k<maxn,那么在前k天仓库一定是满的,第k+1天早上是满的,晚上有k+1只鸟来吃,仓库就剩maxn-(k+1),第k+2天早上添加k个,此时仓库就有maxn-(k+1)+k,晚上k+2只鸟来吃就剩maxn-(k+1)+k-(k+2)=maxn-k-1-2...依此类推第k+m天晚上仓库就剩maxn-k-1-2-...-m=maxn-k-(m*(1+m)/2),假设第k+m天仓库第一次为空,根据maxn-k-(m*(1+m)/2)=0求解m,如果m-(ll)m>0,天数就加1,最后仓库第一次为空的天数就是k+m
代码:
#include <iostream>#include <algorithm>#include <string>#include <cstring>#include <cmath>#include <cstdio>using namespace std;typedef long long int ll;int main(){ ll maxn,k; while(scanf("%I64d%I64d",&maxn,&k)==2) { if(k>=maxn) { printf("%I64d\n",maxn); } else { double day1=(-1+sqrt(1-8*(k-maxn)))/2; ll day; if(day1-(ll)day1>0)day=day1+1; else day=day1; printf("%I64d\n",day+k); } } return 0;}
阅读全文
0 0
- 【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 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 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 Round #404 C. Anton and Fairy Tale
- Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale
- codeforces round#404(div.2) C. Anton and Fairy Tale
- Codeforces #404 (Div. 2) C. Anton and Fairy Tale (二分
- BZOJ 2194 快速傅立叶之二
- Deepin下安装Oracle Java出现Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=gasp问题解决方案
- N/D to float number
- 隐藏某一个cell的分割线
- PSQL 连接Postgres数据库
- Codeforces 785C Anton and Fairy Tale
- Codeforces Round #423 (Div. 2) C. String Reconstruction
- Git step by step
- 操作系统中读者-写者问题的一点疑问
- maven版本号定义约定
- 51nod 1449 砝码称重(思维+进制)
- POJ 3164 Command Network 笔记
- POJ 2991:Crane
- 程序随笔——timestamp(时间戳)