Drying (二分)

Problem 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
<span lang="en-us"><p>The first line contains a single integer <i>n</i> (1 ≤ <i>n</i> ≤ 100 000). The second line contains <i>a<sub>i</sub></i> separated by spaces (1 ≤ <i>a<sub>i</sub></i> ≤ 10<sup>9</sup>). The third line contains <i>k</i> (1 ≤ <i>k</i> ≤ 10<sup>9</sup>).</p></span>

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

Sample Input
<b>sample input #1</b> 3 2 3 9 5 <b>sample input #2</b> 3 2 3 6 5

Sample Output
<b>sample output #1</b> 3 <b>sample output #2</b> 2

题目大概:

一道关于把衣服晾干的题,这道题中衣服一分钟掉一单位的水,吹风机一分钟掉k单位的水,给出衣服的湿度,问最少几分钟。

思路:

需要注意的是,这k单位包含自然风干的一单位的水,这是最坑爹的,在这里很容易出错。然后,自然是二分时间,然后看看是否能够晾干,再分情况赋值,值得一提的是这里要向上取整。在整数运算中a/b的向上取整为(a+b-1)/b。

代码:


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long n;
long long a[100005];
long long k;

int pan(long long mid)
{   long long sun=0;

    for(long long i=1;i<=n;i++)
    {
     if(a[i]>mid)
     {
         sun+=(a[i]-mid+k-2)/(k-1);
         if(sun>mid)return 0;
     }

    }

    return 1;



}

int main()
{
    while(scanf("%I64d",&n)!=EOF)
    {
    for(int i=1;i<=n;i++)
    {
        scanf("%I64d",&a[i]);

    }
    scanf("%I64d",&k);
    sort(a+1,a+1+n);
    if(k==1)
    {printf("%I64d\n",a[n]);
    continue;
    }
    long long l,r,mid;
    l=1;
    r=a[n];
    int aa;
        while(l<=r)
    {
        mid=(l+r)/2;
        if(pan(mid))
        {  aa=mid;
            r=mid-1;
        }
        else
        {
            l=mid+1;
        }

    }


    printf("%d\n",aa);
    }
    return 0;
}


### MMC功率子模块故障类型及其分类 在多电平变换器(MMC)中,功率子模块(SM)作为基本单元起着至关重要的作用。SM内部元件可能出现多种类型的故障,这些故障可以依据其特性分为不同类别。 #### 一、按故障性质划分 1. **硬开关故障** 这类故障通常发生在半导体器件上,在非零电压或电流条件下发生状态转换,可能导致过热甚至永久损坏[^1]。 2. **软启动失败** 当MMC中的某个子模块无法正常完成初始化过程时,则会发生此类情况;这可能是由于控制逻辑错误或是电源供应问题引起[^2]。 #### 二、基于受影响组件的不同来区分 1. **IGBT/FET相关故障** 绝缘栅双极晶体管(Insulated Gate Bipolar Transistor, IGBT) 或场效应晶体管(Field Effect Transistor,FET) 是构成SM的核心部件之一。它们容易遭受短路击穿、开路失效等问题的影响[^3]。 2. **电容器件异常** 直流侧支撑电容以及交流侧滤波用电容也属于常见易损部位。电解质干涸造成的容量下降、漏液引发的安全隐患都是不容忽视的因素[^4]。 ```python class FaultType: def __init__(self,name,detail): self.name=name self.detail=detail hard_switch_fault = FaultType('Hard Switching Failure','occurs under non-zero voltage/current conditions') soft_start_failure = FaultType('Soft Start Failure', 'due to control logic errors or power supply issues') igbt_related_fault = FaultType('IGBT/FET Related Failures','short circuit breakdown and open-circuit failure') capacitor_abnormality = FaultType('Capacitor Abnormities','electrolyte drying leading capacity reduction and leakage hazard') ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值