网站开发中点赞怎么做到的,广西建设网个人登录,wordpress静态,seo关于网站搜索排名烘干衣服 题目大意#xff1a;主人公有一个烘干机#xff0c;但是一次只能烘干一件衣服#xff0c;每分钟失水k个单位的水量#xff0c;自然烘干每分钟失水1个单位的水量#xff08;在烘干机不算自然烘干的那一个单位的水量#xff09;#xff0c;问你最少需要多长时间烘… 烘干衣服 题目大意主人公有一个烘干机但是一次只能烘干一件衣服每分钟失水k个单位的水量自然烘干每分钟失水1个单位的水量在烘干机不算自然烘干的那一个单位的水量问你最少需要多长时间烘干衣服 简单来说题目就是要时间允许的情况下让时间最小时间可以无限大这题就是“最小化最大值”二分法 1 #include iostream2 #include functional3 #include algorithm4 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)//在时间允许的情况下让值最小最小化最大值
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]);//注意一定不要出现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)10e9 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 } 转载于:https://www.cnblogs.com/Philip-Tell-Truth/p/5130951.html