日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 760B 】Frodo and pillows (二分题意,注意细节)

發布時間:2023/12/10 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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 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.

題目大意:

n個人(包括Frodo)在Frodo家里過夜,家里有n張床和m個枕頭,每個人都至少一張床和一個枕頭,但是每個人都想得到盡可能多的枕頭,但是如果有任何一個人的枕頭至少比他的鄰居少兩個,那么就會受傷。(對應那句but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.)Frodo睡在第k個位置(k<=n),問:在沒有人受傷的情況下,Frodo最多能得到多少個枕頭。

解題報告:

? ? 這題如果構造的話,情況就太多了,,但是我們可以枚舉枕頭數啊,因為當主人公的枕頭數定下來之后,就很好得到每一次的最優構造了,就是一個簡單的數學求和公式了。代碼寫的很冗長,但是思路很簡單。我只是分了情況(在兩邊和不在兩邊)。

AC代碼:

#include<bits/stdc++.h> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; ll n,m,k; bool ok1(ll x) {ll res = 0;if(n < x) res = ((x-n+1) + x) * n / 2;else res = (1+x)*x/2;return res <= m; } bool ok2(ll x) {ll res1,res2;if(k < x) res1 = ((x-k+1)+x)*k/2;else res1 = (1+x)*x/2;if(n-k+1 < x) res2 = ((x-(n-k+1)+1)+x)*(n-k+1)/2;else res2 = (1+x)*x/2;return res1 + res2 - x <= m; } int main() {cin>>n>>m>>k;//n人 m枕頭 在第k個 if(n == m) {printf("1");return 0;}m=m-n;//默認每個人有一個ll l = 0,r = m;ll ans = 0;ll mid = (l+r)>>1;if(k == 1 || k == n) {k=1;while(l <= r) {mid = (l+r)>>1;if(ok1(mid)) {ans=mid;l=mid+1;}else r=mid-1;}}else {while(l<=r) {mid = (l+r)>>1;if(ok2(mid)) {ans = mid;l=mid+1;}else r=mid-1;}}printf("%lld\n",ans+1);return 0 ;}

總結:

? 注意一個細節就是ok2函數中構造的時候,中間那條邊會被計算兩次,舉個例子

? 樣例:

? ?4 8 2

? ?應該輸出3,結果輸出了2。就是因為,x=3的時候,本來用不到m塊枕頭,但是你重復計算了一次,所以就多算了枕頭數,所以就返回了false了、、、

總結

以上是生活随笔為你收集整理的【CodeForces - 760B 】Frodo and pillows (二分题意,注意细节)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产91在线视频 | 亚洲第十页 | 骚虎av在线| 超碰人人在线观看 | 日本中文字幕在线观看 | 91精品视频在线 | 国产精品美女久久久久久 | 日本免费一区二区三区最新 | 久久国产人妻一区二区免色戒电影 | 91在线视频免费 | 欧美mv日韩mv国产 | 亚洲美女在线播放 | 欧美人吸奶水吃奶水 | 韩国三级hd中文字幕叫床浴室 | 不用播放器看av | 在线亚洲综合 | 一本色道久久综合亚洲二区三区 | 91网站观看 | 欧美成人二区 | 在线看毛片网站 | 色欲AV无码精品一区二区久久 | 国产精品一区二区三区四区五区 | 国产三级理论片 | 黄色香蕉视频 | 欧美日韩成人免费 | 五月激情六月 | 找av123导航| 久久er99热精品一区二区介绍 | 丝袜美腿中文字幕 | 免费一区二区三区四区 | 都市豪门艳霸淫美妇 | 精品无码人妻一区二区三区品 | 国产一级在线观看 | 免费黄在线看 | 亚洲成人自拍偷拍 | 奇米精品一区二区三区四区 | 亚洲永久在线 | av不卡免费在线 | 欧美怡红院一区二区三区 | 久久尹人| 国产欧美精品一区二区色综合 | 一区二区不卡视频在线观看 | 天堂网2014| 影音先锋91| 91免费视频网址 | 麻豆成人精品国产免费 | 中文字幕日韩电影 | 国产一区a| 成人小说亚洲一区二区三区 | 欧美精品手机在线 | 国产97色在线 | 日韩 | 色哟哟一区二区三区四区 | www黄色网址 | 毛片在线播放视频 | 强伦轩人妻一区二区电影 | 国产全肉乱妇杂乱视频 | 精东传媒在线观看 | 一区二区三区国产视频 | 亚洲一区二区三区四区在线观看 | xxxwww黄色| 秋霞午夜视频 | 国产123在线 | 色乱码一区二区三区网站 | 伊人小视频 | 精品久久人人妻人人做人人 | 精品丝袜一区 | 国产免费福利视频 | 日日操影院| 久久伊人中文字幕 | 人与禽性7777777 | 免费在线日韩 | 好吊妞一区二区三区 | 一级特黄性色生活片 | 五月婷婷开心 | 9久久9毛片又大又硬又粗 | 日韩免费二区 | 看免费黄色片 | 一级做a爰片久久毛片潮喷 天天透天天干 | 日日摸天天爽天天爽视频 | 欧美成人片在线观看 | 公车激情云雨小说 | 性久久久久久久久 | 日韩精品中文在线 | 色婷av| 国产欧美久久久精品免费 | 久综合| 男女插插视频 | 国产精品久久久99 | 国产伦精品一区二区三区免费迷 | 午夜影院a | 亚洲美女屁股眼交 | 久久精品国产99国产 | 亚洲乱码国产乱码精品精剪 | 四虎在线播放 | 国产777 | 青青草免费观看 | 亚洲日本欧美 | 69xx国产 | 天天想你在线观看完整版电影免费 |