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的更多相关文章
随机推荐
- poj1125
题目大意:哎,意思看了半天,看了别人的解释才明白,就是说从一个经纪人出发传递消息,直到所有人都收到消息 也就是说只要找到该经纪人到其它所有点的最短距离中的最大一个时间,就说明最后一个也收到消息了. 而 ...
- php中strpos()函数
1,strpos()函数 mixed strops(]) 返回needle在haystack中首次出现的数字位置,从0开始查找,区分大小写. 参数:haystack,在该字符串中进行查找. needl ...
- php文件每隔几秒执行一次
说实话,linux 下面的crontab 任务完全可以实现所有的定时任务脚本,但是有些脚本只需要在一段时间内执行,过了这段时间之后,就不再执行定时脚本了.在使用crontab的时候,就需要人为的关闭掉 ...
- POJ 1014
#include<iostream>#include<stdio.h>#define num 6using namespace std; bool DFS(int i,int ...
- 多线程编程,CPU是如何解决多线程内存访问问题的
CPU对内存变量的修改是先读取内存数据到CPU Cache中,然后再由CPU做运算,运算完成后继续写入到内存中 在单核CPU中,这完全没有问题,然而在多核CPU中,每一个CPU核心都拥有自己独立的Ca ...
- @JsonView注解的使用
看到一个新的注解以前没有用过,记录一下使用方法. 注意是:com.fasterxml.jackson.annotation.JsonView @JsonView可以过滤pojo的属性,使Control ...
- sql 函数字符串处理
--Description: 字符处理 --使用: 放到查询分析器里执行就可以了 --示例: select * from dbo.splitstr('12 44 45 50 56 87',' ') o ...
- Oracle 12c 建表空间语句
create tablespace TBS_DYS datafile 'D:/Oracle_12c/app/dingyingsi/oradata/dingyingsi/TBS_DYS.ba' size ...
- CentOS SVN Failed to load JavaHL Library
在CentOS 6上的eclipse安装了svbclipse插件后,svn不能使用,并且第一次使用的时候还出现下面错误窗口提示 Failed to load JavaHL Library. These ...
- Nginx设置静态页面压缩和缓存过期时间的方法
使用nginx服务器的朋友可能都知道需要设置html静态页面缓存与页面压缩与过期时间的设置了,下面我来给各位同学介绍一下配置方法,包括对ico,gif,bmp,jpg,jpeg,swf,js,css, ...