zoj3778 Talented Chef
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 <= N, M <= 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(表示有n道菜)、m(表示能同时煮m道菜),给出每道菜的时间,求最少需要煮多久。
思路:直接比较时间最长那道菜和总时间除以m的值哪个最大,取最大的即可。因为要嘛就是煮完的时候要嘛就是时间最长那道菜的时间,要嘛就是总时间除以m。
代码如下
/*
* Author: Joshua
* Created Time: 2014/5/18 13:30:03
* File Name: c.cpp
*/
#include<cstdio> void solve()
{
int n,m,max=,ans,sum=;
int a[];
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
{
scanf("%d",&a[i]);
if (a[i]>max) max=a[i];
sum+=a[i];
}
if ((sum-)/m+ >max) printf("%d\n",(sum-)/m+);
else printf("%d\n",max);
} int main()
{
int times;
scanf("%d",×);
while (times)
{
times--;
solve();
}
return ;
}
zoj3778 Talented Chef的更多相关文章
- Talented Chef(简单题,被我想的太复杂了,用复杂的方法当然会超时咯,由此可见,并非所有题都是想的越多越好)
Description As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the ...
- Talented Chef ZOJ - 3778
As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the same time. ...
- ZOJ 3778:Talented Chef(贪心?思维)
Talented Chef Time Limit: 2 Seconds Memory Limit: 65536 KB As we all know, Coach Gao is a talented c ...
- ZOJ 3778 Talented Chef(找规律,模拟计算,11届ACM省赛,简单)
题目链接 2014年浙江省赛C题,当时觉得难,现在想想这题真水.. 找规律: 若 最大的那个步骤数*m-总和>=0,那么答案就是 最大的那个步骤数 . 否则 就要另加上不够的数量,具体看代 ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- ZOJ 3778 Talented Chef
题目链接 题意 : 这个人需要做n道菜,每道菜Ai步,他可以同时做M道不同的菜的其中一步,问你最少需要多少时间能做完所有的菜. 思路 : 这个题比赛的时候禁锢思路了,根本没想出来,就是当M > ...
- ZOJ 3778 Talented Chef 模拟 [ 祝愿明天省赛一帆风顺, ZJSU_Bloom WILL WIN : )
这题的意思是给你 n 道菜,第 i 道菜需要 Ai 步才能完成 每次你能对 m 道菜分别完成一步,请问最少需要几次? 这题暴力写肯定是不行的,去年省赛的时候就是没写出来这题,今天再把思路理一理吧. 首 ...
- ZOJ 3778 C - Talented Chef 水题
LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3778 题意:有n道菜,每道菜需要\(a_i\)道工序,有m个锅可 ...
- ZOJ3778--一道水题
Description As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the ...
随机推荐
- HDOJ2003-求绝对值
Problem Description 求实数的绝对值. Input 输入数据有多组,每组占一行,每行包含一个实数. Output 对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果 ...
- [js] post 方式打开新窗口
一.前因 一般我们是用 window.open(url,name,params); 打开新窗口, url 会携带一些参数, 但存在参数过多,引发url 过长截断,无法打开正确窗口, 所以我们需要使用 ...
- 【CSS】background 的覆盖
1. 样式覆盖问题描述 现象:class1 为dom节点默认样式,class2为dom节点后增加样式,发现class2的background 被class1的覆盖 解决办法:在class2 的back ...
- javascript编程解决黑化的牛牛问题
问题描述 时间限制:1秒 空间限制:32768K 牛牛变得黑化了,想要摧毁掉地球.但他忘记了开启地球毁灭器的密码.牛牛手里有一个字符串S,牛牛还记得从S中去掉一个字符就恰好是正确的密码,请你帮牛牛求出 ...
- Bean 的生命周期 之 后处理Bean
这里先把Bean 的生命周期总结一下,然后引出后处理Bean 首先,Bean 的生命周期总共有11步: 1.instantiate bean对象实例化 2.populate properties 封装 ...
- Java 数组初始化与定义的解惑
- year:2017 month:7 day:17
2017-07-17 JavaScript 1.javascript 中的运算符 (1)算数运算符:+ ,- ,* ,/ ,% (2)位运算符:& ,| ,~ ,^ ,<< (左 ...
- 7. leetcode 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- 一步一步学Vue(十二)
为了提升代码的逼格,之后代码改为Vue文件组件,之前代码虽然读起来容易理解,而且适合在小的项目中使用,但是有如下缺点: 全局定义(Global definitions) 强制要求每个 componen ...
- AndroidTv开发中常用的adb命令
盒子应用开发时,调试比手机上的开发比较麻烦一点,而且需要经常跟 adb 打交道,不管是 wifi 连接调试,还是应用删除安装等.这里记录一些常用的操作,方便查阅. adb wifi连接调试 方法一:需 ...