kuangbin [two points] HDU 3104 Drying (integer two points)

Insert picture description here
The meaning of the question:
Every piece of clothing has a certain unit of water. Without the use of a dryer, each piece of clothing will naturally lose 1 unit of water per minute, but if the dryer is used, it will lose K units of water per minute. Unfortunately, there is only one dryer. Each dryer can only dry one piece of clothes at the same time. How long does it take to dry N pieces of clothes at least?

Solution: To be updated~~

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<algorithm>

#define ll long long
#define int ll
#define inf 0x3f3f3f3f
#define PI acos(-1.0)
using namespace std;
int read() {
    
    
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') {
    
     if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') {
    
     s = s * 10 + ch - '0';    ch = getchar(); }
	return s * w;
}
int gcd(int x, int y) {
    
     return y ? gcd(y, x % y) : x; }
int ksm(int a, int b, int mod) {
    
     int s = 1; while(b) {
    
    if(b&1) s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
const int N = 100010;
int n, k; //n件衣服 ,k是一分钟能烘干的水量 
int a[N];//水分 
bool check(int mid) {
    
    
	int sum = 0;
	for (int i = 0; i < n; ++i) {
    
    
		//如果自然风干的时间不够,那么就需要使用洗衣机 
		if (a[i] > mid) {
    
    
			int t = ceil((a[i] - mid) * 1.0 / (k - 1));//公式推导
			sum += t;
		}
	}
	return sum > x;
}
signed main()
{
    
    
	while (~scanf("%lld", &n)) {
    
    
		int maxx = 0;
		for (int i = 0; i < n; ++i) {
    
    
			scanf("%lld", &a[i]);
			//可以取一个最大值作为二分的上界 
			maxx = max(maxx, a[i]);
		}
		k = read();//k为一分钟能烘干的水量
		if (k == 1) {
    
    
			printf("%lld\n", maxx);
			continue;
		}
		int l = 0, r = maxx + 10;
		while (l < r) {
    
    
			int mid = l + r >> 1;
			if (check(mid))
				l = mid + 1;
			else
				r = mid;
		}
		printf("%lld\n", r);
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/m0_46272108/article/details/109431507