D - Frodo and pillows CodeForces - 760B
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.
Example
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.
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
#define LL long long int
const LL INF = 1e9 + 5;
int n, m, k;
LL Sum(LL a, LL b)
{if (b == 0)return 0;LL tmp=min(a,b);//LL tmp2 = max(a, b);tmp = (a*2-tmp+1)*tmp / 2;return tmp;
}
bool check(LL tmp)
{LL p, q,ans=0;p = k - 1;//Lq = n - k + 1;//Rif (p < 0)p = 0;if (q < 0)q = 0;ans += Sum(tmp-1,p) + Sum(tmp,q);if (ans <= m){return 1;}return 0;
}
int main()
{ while (cin >> n >> m >> k){LL L = 0, R = INF, mid;m -= n;//L+1while (L < R){mid = (L + R) / 2;if (check(mid)){L = mid+1;}else{R = mid;}}cout << L << endl;}return 0;
}
D - Frodo and pillows CodeForces - 760B相关推荐
- Frodo and pillows CodeForces - 760B 二分 注意l和r的选择
以后写l和r的初始值的时候,在不影响合理性的前提下,尽量写大一点 比如下面这个代码,如果r不加以或者l==0就不行 #include <iostream> #include <cst ...
- 【CodeForces - 760B 】Frodo and pillows (二分题意,注意细节)
题干: n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row a ...
- Codeforces Roud#393
B. Frodo and pillows time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForces 375D Tree and Queries
传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...
- 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)
题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...
- 【codeforces 812C】Sagheer and Nubian Market
[题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...
- CodeForces 获得数据
针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...
- codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...
题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...
- CodeForces 595A
题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...
- codeforces A. Jeff and Digits 解题报告
题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...
最新文章
- android NinePatch图片制做
- 《计算机组成与设计(ARM版)》读书笔记-第二章指令2
- java 中while编译之后_从APK反编译的Java-while循环什么也不做
- $JavaScript(3)
- 有关 Lambda linq练习 有待整理
- Eclipse项目无错误但是有红叉问题解决
- php期末作业经验,期末作业.php
- Java垃圾回收GC概览
- Linux: Shared MIME
- iOS 使用UIView的一种有效方法
- 分布式存储系统学习笔记(二)—分布式文件系统(1)—Google文件系统GFS
- Python中,如何使用ImageDraw在Image上绘制粗线?
- pyqt 子窗口控制主窗口绘图_PyQtGraph如何关闭绘图窗口/关闭所有绘图窗口?
- python函数中文手册-python函数手册
- 单机倒立摆系统建模与仿真
- 清华大学团队:人脸识别爆出巨大丑闻,15分钟解锁19款手机
- fragstats教程
- 今天看到标题 《 章子怡低胸礼服亮相(组图)》
- python中使用“[函数名].[变量名]”声明变量
- 使用MSHTML解析HTML代码