CodeForces760B
B. Frodo and pillows
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?
Input
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.
Output
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
Examples
input
4 6 2
output
2
input
3 10 3
output
4
input
3 6 1
output
3
Note
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.
以k位置为中心,枕头数量向两侧递减。二分搜索答案。
//2017.01.31
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int main()
{
int n, m, k;
while(cin>>n>>m>>k)
{
m -= n;
long long lp = k-, rp = n-k;
long long l = , r = m, mid, ans;
while(l<=r)
{
mid = (l+r)>>;
long long tmp = mid;
if(mid>=lp)tmp += (mid*-lp-)*lp/;
else tmp += (mid-)*mid/;
if(tmp > m){r = mid-;continue;}
if(mid>=rp)tmp += (mid*-rp-)*rp/;
else tmp += (mid-)*mid/;
if(tmp < m){
ans = mid+;
l = mid+;
}
else if(tmp > m)r = mid-;
else{
ans = mid+;
break;
}
}
cout<<ans<<endl;
} return ;
}
CodeForces760B的更多相关文章
随机推荐
- 5.python内置函数详解
内置函数 声明,转载至这位大哥,感谢之至 http://blog.csdn.net/oaa608868/article/details/53506188 关于分类 数学运算(7个) 类型转换(24个) ...
- clang 编译 OC
clang -fobjc-arc -framework Foundation helloworld.m -o helloworld.out OVERVIEW: clang LLVM compiler ...
- elasticsearch 分片(Shards)的理解
分片重要性 Es中所有数据均衡的存储在集群中各个节点的分片中,会影响ES的性能.安全和稳定性, 所以很有必要了解一下它. 分片是什么? 简单来讲就是咱们在ES中所有数据的文件块,也是数据的最小单元块, ...
- 1. Python中如何使用其他语言?(python的胶水作用,python又叫胶水语言)
1. python中如何插入C语言运行? (1)编写C语言代码: #include<stdio.h> void CFun() { printf("---------我是c语言:- ...
- WebDriverAPI(6)
在指定元素上方进行鼠标悬浮 测试网址 http://www.baidu.com Java语言版本实例 @Test public void roverOnElement() { driver.manag ...
- GDAL VS2010 win7(64位)安装、使用说明(图文解析)
一.电脑配置及安装版本 Win 7(64位机) Visual Studio 2010 GDAL 1.9.2(我也尝试了最新版GDAL1.11.0,应该同样可以用的,只是在重新配置时又选用了老一点的版本 ...
- 我与GitHub的第一次——自制音乐文件修改器
背景: 随机播放,所有的音乐播放器里面现在几乎都有这个功能吧.但是有没有发现,自己的播放器在选择随机播放的时候,经常会听到重复顺序的歌曲呢?反正我是有这样的感觉,无耐自己平时下的歌曲都是“歌手名—歌曲 ...
- Linux 系统计算文件夹下文件数量数目
查看某目录下文件的个数(未包括子目录) ls -l |grep "^-"|wc -l 或 find ./company -type f | wc -l 查看某目录下文件的个数,包括 ...
- gitlab+jenkins+hook代码自动构建发布上线
Gitlab+Jenkins+Hook 1.gitlab和jenkins的安装见: http://www.cnblogs.com/cuishuai/p/7544663.html http://www. ...
- (转) Java我的高效编程之环境搭建
前言:刚毕业, 工作之余写博客有利于提高技术,更是能帮助人,接下来会认认真真写好每一篇博客.希望大家多多支持.废话不多说,马上开始.这是一篇环境搭建的博客. jdk+eclipse+svn+maven ...