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 }







  • 相关阅读:
    异常处理(throw,throws,try,catch,finally)
    内部类、匿名内部类、静态内部类
    Object,equals,toString
    有关于多态和静态绑定与动态绑定的知识
    接口的基本知识
    关于继承的基本知识,方法重写,final和abstract的使用, 动态绑定和静态绑定的知识
    设计模式: 单列设计模式 、模块方法设计模式、装饰设计模式、工厂设计模式、适配器设计模式
    zabbix设置维护周期
    zabbix入门
    yum安装zabbix 5.0 LTS
  • 原文地址:https://www.cnblogs.com/tom987690183/p/3661320.html
Copyright © 2011-2022 走看看