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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

POJ 3104 Drying [二分 有坑点 好题]

發布時間:2024/1/17 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 3104 Drying [二分 有坑点 好题] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

傳送門

表示又是神題一道

Drying
Time Limit:?2000MS?Memory Limit:?65536K
Total Submissions:?9327?Accepted:?2364

Description

It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She is not afraid of this boring process. Jane has decided to use a radiator to make drying faster. But the radiator is small, so it can hold only one thing at a time.

Jane wants to perform drying in the minimal possible time. She asked you to write a program that will calculate the minimal time for a given set of clothes.

There are?n?clothes Jane has just washed. Each of them took?ai?water during washing. Every minute the amount of water contained in each thing decreases by one (of course, only if the thing is not completely dry yet). When amount of water contained becomes zero the cloth becomes dry and is ready to be packed.

Every minute Jane can select one thing to dry on the radiator. The radiator is very hot, so the amount of water in this thing decreases by?k?this minute (but not less than zero — if the thing contains less than?k?water, the resulting amount of water will be zero).

The task is to minimize the total time of drying by means of using the radiator effectively. The drying process ends when all the clothes are dry.

Input

The first line contains a single integer?n?(1 ≤?n?≤ 100 000). The second line contains?ai?separated by spaces (1 ≤?ai?≤ 109). The third line contains?k?(1 ≤?k?≤ 109).

Output

Output a single integer — the minimal possible number of minutes required to dry all clothes.

Sample Input

sample input #1 3 2 3 9 5sample input #2 3 2 3 6 5

Sample Output

sample output #1 3sample output #2 2

Source

Northeastern Europe 2005, Northern Subregion

?

本來想貪心的,結果越寫越亂,老老實實二分。。。不過這題有其精妙之處,wa的人先看樣例

?

送點test data給WA的朋友們……

Posted by MIRKING at 2008-07-31 13:39:06 on Problem 3104 and last updated at 2008-07-31 13:40:02


test data: 2 8 9 2 result:6 7 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 2 result:875000000

















Re:為什么二分時 枚舉的時間l,r,mid不用__int64就wa了

Posted by wangyaoxuan at 2010-10-14 11:30:23 on Problem 3104
In Reply To:為什么二分時 枚舉的時間l,r,mid不用__int64就wa了 Posted by:wangyaoxuan at 2010-10-14 11:22:39
表示理解了,因為過程中求得的時間值t會超過int,后來的wa們慢慢體會....

?

Posted by lgq1205 at 2009-12-03 12:54:33 on Problem 3104


二分枚舉時間,判斷可行性,然后求解即可.注意判斷可行性的過程:1.先把所有衣服的含水量減去T 2.然后把>=(k-1)的拿去烘干,可以理解為烘干時候每分鐘掉(k-1)水,這樣所有的衣服都每分鐘自然干掉1水了。因為每分鐘掉一滴水是肯定的了,因此,如果你去烘干它的話,那么它就能再掉多k-1 + 1 == k,這樣才是k滴水,然后就是計算總花費時間 3.最后判斷總花費時間時候小于T,若小于等于,則可行性,否則不可行.

如果你WA了,看一下是否有變量要設為64位int,如果RE了,看一下除零。。。

Posted by 2745972075 at 2014-07-21 15:47:54 on Problem 3104


?

1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue> 8 #include<map> 9 #include<set> 10 #include<stack> 11 #include<string> 12 13 #define N 100005 14 #define M 10 15 #define mod 1000000007 16 //#define p 10000007 17 #define mod2 1000000000 18 #define ll long long 19 #define LL long long 20 #define eps 1e-9 21 //#define inf 0x3fffffffff 22 #define maxi(a,b) (a)>(b)? (a) : (b) 23 #define mini(a,b) (a)<(b)? (a) : (b) 24 25 using namespace std; 26 27 int n; 28 ll ans; 29 ll a[N]; 30 ll k; 31 32 void ini() 33 { 34 ans=0; 35 int i; 36 for(i=1;i<=n;i++){ 37 scanf("%I64d",&a[i]); 38 } 39 scanf("%I64d",&k); 40 sort(a+1,a+1+n); 41 } 42 43 int ok(ll m) 44 { 45 int i; 46 ll le=m; 47 ll re; 48 for(i=1;i<=n;i++){ 49 re=a[i]-m; 50 if(re<=0) continue; 51 le-=(re+k-2)/(k-1); 52 } 53 if(le>=0) return 1; 54 return 0; 55 } 56 57 void solve() 58 { 59 ll l=1; 60 ll r=a[n]; 61 ll m; 62 //printf(" %d\n",a[1]); 63 if(k==1){ 64 ans=a[n];return; 65 } 66 while(l<r) 67 { 68 m=l+(r-l)/2; 69 if(ok(m)==1){ 70 r=m; 71 } 72 else{ 73 l=m+1; 74 } 75 } 76 ans=l; 77 } 78 79 void out() 80 { 81 printf("%I64d\n",ans); 82 } 83 84 int main() 85 { 86 // freopen("data.in","r",stdin); 87 //freopen("data.out","w",stdout); 88 //scanf("%d",&T); 89 //for(int ccnt=1;ccnt<=T;ccnt++) 90 //while(T--) 91 while(scanf("%d",&n)!=EOF) 92 { 93 ini(); 94 solve(); 95 out(); 96 } 97 98 return 0; 99 }

?

轉載于:https://www.cnblogs.com/njczy2010/p/4211555.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的POJ 3104 Drying [二分 有坑点 好题]的全部內容,希望文章能夠幫你解決所遇到的問題。

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