zoj 3778 Talented Chef (思维)

来源:互联网 发布:oa办公系统java源代码 编辑:程序博客网 时间:2024/05/18 00:32

As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the same time. Tonight he is going to have a hearty dinner with his girlfriend at his home. Of course, Coach Gao is going to cook all dishes himself, in order to show off his genius cooking skill to his girlfriend.

To make full use of his genius in cooking, Coach Gao decides to prepare N dishes for the dinner. The i-th dish contains Ai steps. The steps of a dish should be finished sequentially. In each minute of the cooking, Coach Gao can choose at most M different dishes and finish one step for each dish chosen.

Coach Gao wants to know the least time he needs to prepare the dinner.

题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间。

分析:一开始 考虑的是做菜的顺序然后入坑了,其实根本不用考虑顺序,因为工作消耗的量是必然的。所以每分钟都可以消耗m的量,然后求平均值,如果还有余的,加1也必然能怼完,但是这个最短时间不能比最大的量单独做的时间更短。

#include <bits/stdc++.h>using namespace std;int main(){    int t;    cin>>t;    while(t--)    {        int n,m;        scanf("%d%d",&n,&m);        int maxx=0;        int sum=0;        for(int i=0;i<n;i++)        {            int d;            scanf("%d",&d);            maxx=max(maxx,d);            sum+=d;        }        if(n<=m)        {            printf("%d\n",maxx );            continue;        }        else{            int ans=sum/m;            if(sum%m) ans++;            ans=max(ans,maxx);            printf("%d\n",ans );        }    }}
0 0
原创粉丝点击