CodeForces
来源:互联网 发布:淘宝卖家回复买家评价 编辑:程序博客网 时间:2024/06/05 08:26
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 109, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
4 6 2
2
3 10 3
4
3 6 1
3
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
待……
代码:
#include<iostream>#include<cstdio>using namespace std;int n, m, k;int cnt = 1,ans = 1;int main(){ scanf("%d%d%d",&n,&m,&k); m -= n; if(m == 0) return 0 * printf("1\n"); while(m > 0) { if(k + ans <= n) ++cnt; if(k - ans >= 1) ++cnt; m -= cnt; ++ans; } printf("%d\n",ans); return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- nutz dao类
- Declaration of developing a column with respect to Deep Learning
- 怼JAVA第一周,MOCC作业
- 一个PHP+Mysql手工注入例子
- 【Java】の基础——JVM内存区域
- CodeForces
- CSS3 选择器—伪类选择器
- java 希尔排序
- Chrome手势插件
- vue2.0 子组件和父组件之间的传值
- 封装View,封装逻辑,脱光activity
- Discuz!开发之论坛主题列表页标题长度的限制方法
- 深度优先搜索(dfs)
- 使用HTML语言和CSS开发商业站点第一章