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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Allocation Aizu - ALDS1_4_D

發布時間:2024/5/6 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Allocation Aizu - ALDS1_4_D 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

You are given n packages of wi kg from a belt conveyor in order (i=0,1,…n?1). You should load all packages onto k trucks which have the common maximum load P. Each truck can load consecutive packages (more than or equals to zero) from the belt conveyor unless the total weights of the packages in the sequence does not exceed the maximum load P.

Write a program which reads n, k and wi, and reports the minimum value of the maximum load P to load all packages from the belt conveyor.

Input

In the first line, two integers n and k are given separated by a space character. In the following n lines, wi are given respectively.

Output

Print the minimum value of P in a line.

Constraints

1≤n≤100,000
1≤k≤100,000
1≤wi≤10,000

Sample Input 1

5 3
8
1
7
3
9

Sample Output 1

10
If the first truck loads two packages of {8,1}, the second truck loads two packages of {7,3} and the third truck loads a package of {9}, then the minimum value of the maximum load P shall be 10.

Sample Input 2

4 2
1
2
2
6

Sample Output 2

6
If the first truck loads three packages of {1,2,2} and the second truck loads a package of {6}, then the minimum value of the maximum load P shall be 6.

思路

確定最大運載量P時,首先要編寫一個算法來計算k輛以內的卡車總共能裝多少貨物。

思路很簡單,只要卡車的運載量沒達到P,就讓其繼續按順序裝貨物,最后再計算所有卡車運載量的總和即可。

以P為實參,編寫一個返回可裝載貨物數v的函數v=f§,這個函數的算法復雜度為O(n)。

現在只需要調用這個函數,讓P從0開始逐漸自增,第一個讓v大于等于n的P就是答案。但是逐個檢查P會失敗的原因算法復雜度達到O(Pn),程序不可能在限制時間內完成處理。

利用“P增加v不會減少”的性質,用二分搜索來求P,算法復雜度降低至O(n*log P)。

code

/*^....0^ .1 ^1^.. 011.^ 1.0^ 1 ^ ^0.11 ^ ^..^0. ^ 0^.0 1 .^.1 ^0 .........001^.1 1. .111100....01^00 ^ 11^ ^1. .1^1.^ ^0 0^.^ ^0..1.1 1..^1 .0 ^ ^00. ^^0.^^ 0 ^^110.^0 0 ^ ^^^10.01^^ 10 1 1 ^^^1110.101 10 1.1 ^^^1111110010 01 ^^ ^^^1111^1.^ ^^^10 10^ 0^ 1 ^^111^^^0.1^ 1....^11 0 ^^11^^^ 0.. ....1^ ^ ^1. 0^ ^11^^^ ^ 1 111^ ^ 0.10 00 11 ^^^^^ 1 0 1.0^ ^0 ^0 ^^^^ 0 0.0^ 1.0 .^ ^^^^ 1 1 .0^.^ ^^ 0^ ^1 ^^^^ 0. ^.11 ^ 11 1. ^^^ ^ ^ ..^^..^ ^1 ^.^ ^^^ .0 ^.00..^ ^0 01 ^^^ .. 0..^1 .. .1 ^.^ ^^^ 1 ^ ^0001^ 1. 00 0. ^^^ ^.0 ^.1. 0^. ^.^ ^.^ ^^^ ..0.01 .^^. .^ 1001 ^^ ^^^ . 1^. ^ ^. 11 0. 1 ^ ^^ 0.0 ^. 0 ^0 1 ^^^ 0.0.^ 1. 0^ 0 .1 ^^^ ...1 1. 00 . .1 ^^^ ..1 1. ^. 0 .^ ^^ ..0. 1. .^ . 0 ..1 1. 01 . . ^ 0^.^ 00 ^0 1. ^ 1 1.0 00 . ^^^^^^ ..^ 00 01 ..1. 00 10 1 ^^.1 00 ^. ^^^ .1.. 00 .1 1..01 ..1.1 00 1. ..^ 10^ 1^ 00 ^.1 0 1 1.1 00 00 ^ 1 ^. 00 ^.^ 10^ ^^1.1 00 00 10^..^ 1. ^. 1.0 1 ^. 00 00 .^^ ^. ^ 1 00 ^0000^ ^ 011 0 ^. 00.0^ ^00000 1.00.1 11. 1 0 1^^0.01 ^^^ 01.^ ^ 1 1^^ ^.^1 1 0... 1 ^1 1^ ^ .01 ^ 1.. 1.1 ^0.0^ 0 1..01^^100000..0^1 1 ^ 1 ^^1111^ ^^0 ^ ^ 1 1000^.1 ^.^ . 00.. 1.1 0. 01. . 1. .^1. 1 1. ^0^ . ^.1 00 01^.0 001. .^*/ // Virtual_Judge —— Allocation Aizu - ALDS1_4_D.cpp created by VB_KoKing on 2019-05-04:11. /* Procedural objectives:Variables required by the program:Procedural thinking:Functions required by the program:*/ /* My dear Max said: "I like you, So the first bunch of sunshine I saw in the morning is you, The first gentle breeze that passed through my ear is you, The first star I see is also you. The world I see is all your shadow."FIGHTING FOR OUR FUTURE!!! */ #include <iostream> #define MAX 100007 using namespace std;int n,k; long long T[MAX];//k輛最大運載量為p的卡車能裝多少貨物 int check(long long p) {int i=0;for (int j = 0; j < k; j++) {long long s=0;while (s+T[i]<p+1){s+=T[i];i++;if (i==n)return n;}}return i; }int solve() {long long left=0;long long right=100000*10000; //貨物數*1件貨物的最大重量long long mid;while (right-left>1){mid=(right+left)/2;int v=check(mid);if (v>n-1) right=mid;else left=mid;}return right; }int main() {cin>>n>>k;for (int i = 0; i < n; i++)cin>>T[i];long long ans=solve();cout<<ans<<endl;return 0; } 與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的Allocation Aizu - ALDS1_4_D的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 极品白嫩丰满少妇无套 | 国产ts网站 | 自由 日本语 热 亚洲人 | 国产私密视频 | 亚洲人免费视频 | 国内精品久久久久久久久久 | 中文精品久久久久人妻不卡 | 欧美性大战久久久久xxx | 日批视频在线免费看 | 人人看av| 中文久草| 国产成人久久婷婷精品流白浆 | 亚洲专区视频 | 黄网视频在线观看 | 国产成人精品一区二区在线观看 | 欧美激情在线一区 | 国产欧美日韩精品一区二区三区 | www九九热 | 蜜芽一区二区 | 亚洲xxx视频| 蜜臀视频网站 | 天天都色 | 国产精品久久久爽爽爽麻豆色哟哟 | 91视频在线观看视频 | 台湾av在线 | 一区二区美女 | 狠狠操狠狠操 | 中文字幕免费在线看线人动作大片 | 久久久久区 | 波多野结衣一二区 | 亚洲精品小视频 | 天天干中文字幕 | 国产欧美日韩中文字幕 | 欧美一级视频 | 国产黄a三级三级三级 | 久久92| 日韩视频网 | 欧美一区二区在线播放 | 国产在线视频你懂的 | www.成人av.com| 欧美v日本 | 草免费视频| 黄色长视频 | 农村老熟妇乱子伦视频 | 911色| 午夜精品福利在线 | 亚洲精品97久久中文字幕无码 | 精品91在线 | 日本视频在线观看免费 | 亚洲另类视频 | 扒开美女内裤狂揉下部 | 日韩一区二区三区精品 | 久久久久久久久久91 | 久久精品国产99 | 日本美女黄网站 | 国产喷水视频 | 黄色成人av | 福利视频一区二区 | 国产黄视频在线观看 | 久操精品 | 欧美日韩一级大片 | 操操操操操操操操操 | 日韩欧美www| 国产香蕉网 | 色视频网址 | 色av网| 国产精品久久久无码一区 | 激情999| 亚洲av永久无码国产精品久久 | 日韩在线观看第一页 | 亚洲一区二区观看播放 | 色偷偷免费| 欧美国产在线观看 | 给我免费观看片在线电影的 | 欧美国产精品一二三 | 成人av一区二区在线观看 | 精品亚洲国产成av人片传媒 | 亚洲欧美日韩在线一区二区 | 色哟哟视频在线 | 亚洲国产精品自拍视频 | 91九色网| 毛片在线观看网站 | 欧美成人三级在线观看 | 理论片av | 亚洲乱码中文字幕久久孕妇黑人 | 制服丝袜一区 | 人妻一区二区三区免费 | 国产66页 | 天天躁日日躁狠狠躁av | 一本色道久久综合亚洲精品图片 | 婷婷九月 | 涩涩成人网 | 俄罗斯黄色录像 | 国产成人自拍视频在线 | 67194在线免费观看 | 在线成年人视频 | 久久久99精品免费观看 | 欧美一区欧美二区 | 色国产精品 |