题目描述:
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
3 10 3
3 6 1
输出:
2
4
3
题意:
n个床位,m个枕头,第k个位置最多有多少个枕头,其中相邻之间的差<=1;
题解:
以k位置为中心,枕头数量向两侧递减。二分搜索答案。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>