zoukankan      html  css  js  c++  java
  • Talented Chef ZOJ

    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 Mdifferent 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 Tindicating 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

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

    思维题,以平均值来做菜,所用的时间总是最短。

    // Asimple
    #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <queue> #include <vector> #include <string> #include <cstring> #include <stack> #define INF 0x3f3f3f3f #define mod 7 using namespace std; typedef long long ll; typedef unsigned long long ull; const int maxn = 20000+5; int n, m, T, len, cnt, num; void input() { cin >> T; while( T -- ) { cin >> n >> m; int Max = 0; int sum = 0; for(int i=0; i<n; i++) { cin >> num; sum += num; Max = max(Max, num); } cnt = sum/m; if( sum%m ) cnt ++; if( cnt < Max ) cnt = Max; if( m >= n ) cout << Max << endl; else cout << cnt << endl; } } int main() { input(); return 0; }
  • 相关阅读:
    分享20个效果非常绚丽的 CSS3 特性应用演示
    16个优秀的 CSS3 表单开发教程分享
    jQuery 插件列表
    解决PNG图片在IE6下背景不透明的问题让IE6支持PNG透明背景
    20篇教你得到酷炫效果的JQuery教程
    Astar2007初赛第一场的题目
    数据库范式1NF 2NF 3NF BCNF
    Astar2007初赛第一场的题目2
    数字手写识别(VB6)
    DAO 查询Excel中数据时产生“数值字段溢出”
  • 原文地址:https://www.cnblogs.com/Asimple/p/7384080.html
Copyright © 2011-2022 走看看