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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【2019牛客暑期多校训练营(第六场)- D】Move(随机化二分)

發布時間:2023/12/10 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【2019牛客暑期多校训练营(第六场)- D】Move(随机化二分) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

鏈接:https://ac.nowcoder.com/acm/contest/886/D
來源:??途W
?

After the struggle of graduating from college, TangTang is about to move from a student apartment to his new home.

TangTang has n items to move, the i-th of which is of volume viv_ivi?. He can pack all these items into at most K boxes of the same volume.
?

TangTang is so clever that he uses the following strategies for packing items:

?

- Each time, he would put items into a box by the next strategy, and then he would try to fill another box.

- For each box, he would put an unpacked item of the largest suitable volume into the box repeatedly until there is no such item that can be fitted in the box.


Now, the question is what is the minimum volume of these boxes required to pack all items.

輸入描述:

There are multiple test cases. The first line contains an integer T (1≤T≤201 \leq T \leq 201≤T≤20), indicating the number of test cases. Test cases are given in the following.For each test case, the first line contains two integers n, K (1≤n,K≤10001 \leq n, K \leq 10001≤n,K≤1000), representing the number of items and the number of boxes respectively.The second line contains n integers v1v_1v1?, v2v_2v2?, …\ldots…, vnv_nvn? (1≤v1,v2,…,vn≤10001 \leq v_1, v_2, \ldots, v_n \leq 10001≤v1?,v2?,…,vn?≤1000), where the i-th integer viv_ivi? represents the volume of the i-th item.

輸出描述:

For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1, and y denotes the answer to this test case.

示例1

輸入

復制

1 5 3 1 2 3 4 5

輸出

復制

Case #1: 5

題目大意:

你有n件行李,有k個箱子體積相同的箱子,遵循下面的規則將行李放進箱子里面,每次都取當前最大的可以放進箱子的行李放進箱子,如果該箱子放不進任何行李那么就換一個新的箱子再按照這一條規則進行放行李,請問箱子最小的體積是多少,可以放進所有行李。

解題報告:

打眼一看是二分,但是其實并沒有單調性,大概這么理解:假設是這些行李,你如果箱子的體積減小一點,或許就能拿出來一個大行李,放進去更多的小行李。這樣導致后面的箱子需要放的行李的序列和 不減小箱子體積的行李序列是完全不一樣的了,所以答案肯定也會不同,所以不能二分。

這題的正解是我們可以確定一個下界和一個上界,并且這個界的范圍不會很大,所以可以直接在這個上下界內暴力就好。

當然由于不具有二分性質的樣例不好構造,我們可以近似認為這是一個具有二分性質的題目,只不過加點隨機化的思想。注意這題如果先二分完了在最后進行隨機數處理的話也過不去,需要在二分的過程中擴大搜索范圍。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5;int a[MAX]; int n,k; bool ok(int x) {multiset<int> ms;int cnt = 0,res = x;for(int i = 1; i<=n; i++) ms.insert(a[i]);while(1) {if(ms.empty() || cnt == k) break;auto it = ms.upper_bound(res);if(it == ms.begin()) {res = x;cnt++;} else {--it;res -= *it;ms.erase(it);}}if(ms.empty()) return 1;else return 0; } int main() {int t,iCase=0;cin>>t;while(t--) {scanf("%d%d",&n,&k);for(int i=1; i<=n; i++) scanf("%d",a+i);int l = 1,r=1e6,ans=1e6,mid;while(l+20<=r) {mid=(l+r)>>1;int flag = 0;for(int i = mid; i<=mid+10; i++) {if(ok(i)) {flag = 1,r = i-1,ans=i;break;}}if(flag == 0) l = mid+1;}for(int i = max(0,ans-20); i<=ans; i++) {if(ok(i)) {printf("Case #%d: %d\n",++iCase,i);break;}}}return 0; }

?

總結

以上是生活随笔為你收集整理的【2019牛客暑期多校训练营(第六场)- D】Move(随机化二分)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 日本啪啪啪一区二区 | 国产福利在线导航 | 国产精品久久伊人 | 91免费片 | 黄色av电影网站 | 99免费在线 | 色图自拍偷拍 | 国产一区不卡视频 | 一级看片免费视频 | 欧洲久久久久 | 国产一区二区电影 | 欧美性久久久 | 69视频免费 | 欧美日韩免费一区二区三区 | 国产欧美久久一区二区三区 | 成年人午夜 | 91sex国产| 亚洲视频在线视频 | 国产中文字幕一区二区三区 | 一区二区三区国产精品视频 | 欧美大尺度床戏做爰 | 成人性做爰aaa片免费 | 四虎在线免费观看 | 久久机热| 久久99精品久久久久久 | 国产欧美精品aaaaaa片 | 国产福利久久 | 精品人妻aV中文字幕乱码色欲 | 好男人www在线视频 我们的2018在线观看免费高清 | 国产视频久久 | juliaann第一次和老师 | 欧美日韩精品区别 | 樱桃香蕉视频 | 高清欧美性猛交 | 国产无码日韩精品 | 影音先锋亚洲资源 | 91视频最新地址 | 美女又爽又黄免费 | 外国电影免费观看高清完整版 | 亚洲欧美成人一区二区三区 | 亚洲精品av在线 | 天天操操操 | 高清久久 | a色网站| www.人人干 | 伊人性视频 | 丁香九月激情 | 日韩一区二区三区四区五区 | 亚洲网址在线 | 国产一级网站 | 日韩a级大片 | 亚洲最大成人网站 | 新91av| 人与动物黄色片 | 国产素人av | 国产精品夫妻自拍 | 国产成人精品视频一区二区 | 狠狠操一区二区 | 久久妇女 | 成年丰满熟妇午夜免费视频 | 免费观看的av网站 | 欧美骚少妇| 欧美另类视频在线 | 91最新在线视频 | 欧美精品第一页 | 丝袜诱惑一区 | 天堂男人av| 蛇女欲潮性三级 | 91免费版黄| 日本中文字幕在线播放 | 一级特黄视频 | 久久精品人人做人人爽 | 一本色道久久综合精品婷婷 | 色999在线 | 久久久久一区二区三区 | a久久久久 | 美女视频免费在线观看 | 69激情网| 99re6在线视频 | 一级片福利| 不卡在线视频 | av网站亚洲 | 色小说香蕉 | 香蕉久久一区二区三区 | 免费日韩毛片 | 美女交配| 99少妇| 一区二区日韩国产 | av天堂永久资源网 | 日本一区二区三区视频在线播放 | 国产三级理论片 | 久久99精品久久久久久园产越南 | 蛇女欲潮性三级 | 亚洲激情婷婷 | 免费看片成人 | 久久精品成人一区二区三区蜜臀 | 国产做爰免费观看视频 | 久久久久久一区二区 | 99久久伊人|