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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Divide and conquer:Drying(POJ 3104)

發(fā)布時(shí)間:2023/12/2 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Divide and conquer:Drying(POJ 3104) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

                 

                 烘干衣服

  題目大意:主人公有一個(gè)烘干機(jī),但是一次只能烘干一件衣服,每分鐘失水k個(gè)單位的水量,自然烘干每分鐘失水1個(gè)單位的水量(在烘干機(jī)不算自然烘干的那一個(gè)單位的水量),問你最少需要多長時(shí)間烘干衣服?

  簡單來說題目就是要:時(shí)間允許的情況下讓時(shí)間最小,時(shí)間可以無限大,這題就是“最小化最大值”,二分法

  

1 #include <iostream> 2 #include <functional> 3 #include <algorithm> 4 5 using namespace std; 6 7 static int clothes[100005]; 8 9 void Search(const int, const int); 10 bool judge(const long long, const int, const int); 11 int fcmop(const void *a, const void *b) 12 { 13 return *(int *)a - *(int *)b; 14 } 15 16 int main(void)//在時(shí)間允許的情況下讓值最小(最小化最大值) 17 { 18 int sum_clothes, re; 19 20 while (~scanf("%d", &sum_clothes)) 21 { 22 for (int i = 0; i < sum_clothes; i++) 23 scanf("%d", &clothes[i]); 24 scanf("%d", &re); 25 qsort(clothes, sum_clothes, sizeof(int), fcmop); 26 if (re == 1) 27 printf("%d\n", clothes[sum_clothes - 1]);//注意一定不要出現(xiàn)0的情況 28 else 29 Search(sum_clothes, re); 30 } 31 return 0; 32 } 33 34 void Search(const int sum_clothes, const int re) 35 { 36 long long lb = 0, rb = (long long)10e+9 + 1, mid; 37 38 while (rb - lb > 1) 39 { 40 mid = (rb + lb) / 2; 41 if (judge(mid, sum_clothes, re)) rb = mid; 42 else lb = mid; 43 } 44 printf("%lld\n", rb); 45 } 46 47 bool judge(const long long times, const int sum_clothes, const int re) 48 { 49 long long use_time_now, use_sum = 0; 50 int i; 51 52 for (i = 0; i < sum_clothes && clothes[i] <= times; i++); 53 54 for (; i < sum_clothes; i++) 55 { 56 use_time_now = (clothes[i] - times + re - 1 - 1) / (re - 1);//向上取整,要先-1 57 use_sum += use_time_now; 58 if (use_sum > times) 59 return false; 60 } 61 return true; 62 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/Philip-Tell-Truth/p/5130951.html

總結(jié)

以上是生活随笔為你收集整理的Divide and conquer:Drying(POJ 3104)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。