Codeforces 760B Frodo and pillows 【二分】
来源:互联网 发布:插画师培训 知乎 编辑:程序博客网 时间:2024/05/17 09:11
题目链接:http://codeforces.com/contest/760/problem/B
题目大意:
有 n 个床 m 个枕头,每个床上有个人,主人在 第 k 个床上。现在要求让每个人都有一个枕头,且相邻两个人之间的枕头数之差不应超过1。问主人最多能得到多少个枕头。
题解:
二分能得到的枕头数。
代码:
#include <cstdio>#include <iostream>#include <algorithm>using namespace std;int n, m, k;int lft, rgt;inline void quick_IO() { ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); }int main() {quick_IO();cin >> n >> m >> k;m -= n;int ans = 1;lft = rgt = k;while ( m ) {if( lft == 1 && rgt == n ) break;int tp = (rgt-lft+1);if( m >= tp ) {m -= tp;ans ++;rgt ++; lft -- ;rgt = min(n, rgt);lft = max(1, lft);} else break;}ans += (m/(rgt-lft+1));cout << ans << endl;return 0;}
0 0
- Codeforces 760B Frodo and pillows 【二分】
- 【Codeforces 760 B Frodo and pillows】+ 二分
- Codeforces 760B Frodo and pillows【贪心+二分】
- codeforces-760-B Frodo and pillows(二分+数学)
- 【codeforces 760B】Frodo and pillows
- [codeforces 760B]Frodo and pillows
- CodeForces 760B Frodo and pillows
- Codeforces 760B Frodo and pillows
- codeforce 760 B Frodo and pillows 二分搜索
- B. Frodo and pillows
- Codeforces Round #393 (Div. 2) -B. Frodo and pillows(贪心)
- Codeforces Round #393 (Div. 2) B. Frodo and pillows
- Codeforces Round #393 Frodo and pillows
- Codeforces Round #393 (Div. 2) Frodo and pillows
- CodeForces 760BFrodo and pillows
- codeforces-760【B二分】
- Codeforces 760B (二分)
- codeforces 483b Friends and Presents 二分
- JavaScript数组相关方法学习笔记
- PAT乙级真题1062最简分数(20)
- 9-1
- OpenCV 角点检测(二) Harrise
- 【PAT】1080. Graduate Admission
- Codeforces 760B Frodo and pillows 【二分】
- 编写一个符合国情的日期插件
- POI报表
- APK打包过程分析
- POJ 3268Silver Cow Party
- 阶乘尾部包含n个0的最小数字
- 多线程集合队列等等
- 让EFCore更疯狂些的扩展类库(一):通过json文件配置sql语句
- bzoj 2107 Spoj2832 Find The Determinant III