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的更多相关文章
随机推荐
- UIVisualEffectView(高斯模糊效果)
///高斯模糊. UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; tempView. ...
- Flask从入门到精通之Flash消息
请求完成后,有时需要让用户知道状态发生了变化.这里可以使用确认消息.警告或者错误提醒.一个典型例子是,用户提交了有一项错误的登录表单后,服务器发回的响应重新渲染了登录表单,并在表单上面显示一个消息,提 ...
- Memcached 查看列出所有key方法
Memcached没有一个比较简单的方法可以直接象Redis那样keys *列出所有的Session key,并根据key get对应的session内容,但是还是可以查看的 memcached 查看 ...
- day 47 Django 4的简单应用 创建简单的图书管理 (单表的增删改查)
前情提要 Django 已经学了大半.. 很多东西已经能够使用在生产环境当中 一:模糊查询 二:单表删除 三:单表修改 四:图书管理 图书管理操作 视图结构 A:路由层 A :配置路由文件 参数解 ...
- jdbc连接2(不可以注入)
public void login1(String username, String password) throws ClassNotFoundException, SQLException { / ...
- django.db.utils.InternalError: (1050, "Table 'tb_content' already exists")
在goods应用里面写了tb_content数据表的模型类(不该写在这里的),进行了数据迁移,还导入了数据. 在contents应用里也写了tb_content数据表的模型类(应该写在这里的), 解决 ...
- AngularJS学习之旅
开篇 最近由于项目上可能需要用到AngularJS,公司将技术学习.调研的任务安排了下来,因此开始了我的AngularJS学习之路. 在这之前没写过技术博客,主要是由于太懒,另外自愧文笔不好,因此一直 ...
- 一个用JS数组实现的队列
一个用JS数组实现的队列 /*一个用数组实现的队列*/ function Queue(){ this.dataStore = [];//存放队列的数组,初始化为空 this.enqueue = enq ...
- C++的开源跨平台日志库glog学习研究(二)--宏的使用
上一篇从整个工程上简单分析了glog,请看C++的开源跨平台日志库glog学习研究(一),这一篇对glog的实现代码入手,比如在其源码中以宏的使用最为广泛,接下来就先对各种宏的使用做一简单分析. 1. ...
- [转]Elasticsearch Java API总汇
http://blog.csdn.net/changong28/article/details/38445805#comments 3.1 集群的连接 3.1.1 作为Elasticsearch节点 ...