zoukankan      html  css  js  c++  java
  • zoj 3778 Talented Chef

    Talented Chef

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    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.

    Input

    There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

    The first line contains two integers N and M (1 <= NM <= 40000). The second line contains N integers Ai (1 <= Ai <= 40000).

    Output

    For each test case, output the least time (in minute) to finish all dishes.

    Sample Input

    2
    3 2
    2 2 2
    10 6
    1 2 3 4 5 6 7 8 9 10
    

    Sample Output

    3
    10

    题意:每次在n个数字中最多可以取出m个数字,减去1,每次花费1个单位时间 .求最后都为0的最小时间。

    思路:如果m>n,显然只要数字中最大的那个数字的次数。
    否则,我的操作如果能使更多的数字,参与进来减去1,那就好了。
    假设全部都能恰好满足全部m个数字, if(sum%m == 0) cur = sum / m ;
    如果不能,我就多一次 if( sum%m!=0 ) cur = sum / m +1;
    但是还是要和max比较。因为,这个数字至少是要>=max 的。
    取大的那一个。
     1 #include<stdio.h>
     2 
     3 int main()
     4 {
     5     int T;
     6     int i,max,x,sum,n,m;
     7     scanf("%d",&T);
     8     while(T--)
     9     {
    10         scanf("%d%d",&n,&m);
    11         max=-1;
    12         sum=0;
    13         for(i=1;i<=n;i++)
    14         {
    15             scanf("%d",&x);
    16             sum=sum+x;
    17             if(x>max) max=x;
    18         }
    19         if(m>=n) {printf("%d
    ",max);continue;}
    20         if(sum%m==0)
    21         sum=sum/m;
    22         else sum=sum/m+1;
    23 
    24         if(sum<max) sum=max;
    25         printf("%d
    ",sum);
    26 
    27     }
    28     return 0;
    29 }







  • 相关阅读:
    docker的安装
    Linux的常用命令
    HTTP协议,HTTPS协议,Websocket协议
    常用排序
    go的数组,切片,map
    if-else,switch,for循环
    go的函数,包以及mode的补充
    Android学习笔记——从源码看Handler的处理机制
    ElementUI
    关于IO的理解
  • 原文地址:https://www.cnblogs.com/tom987690183/p/3661320.html
Copyright © 2011-2022 走看看