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 ...
随机推荐
- maven引入已经拥有的jar包
<!-- https://mvnrepository.com/artifact/jfree/jcommon --><dependency> <groupId> ...
- Java虚拟机--垃圾收集
Java虚拟机 1. JVM运行时数据区域 参考书籍:<深入理解Java虚拟机:JVM高级特性与最佳实践,第二版> 资料参考:http://blog.csdn.net/nms312/art ...
- HDU 6040---Hints of sd0061(STL)
题目链接 Problem Description sd0061, the legend of Beihang University ACM-ICPC Team, retired last year l ...
- 【HTML】section
1. 定义 标签定义文档中的节(section.区段).比如章节.页眉.页脚或文档中的其他部分. 2. div.section . article的区别 div: 本身没有任何语义,用作布局以及样式 ...
- MySql 求一段时间范围内的每一天,每一小时,每一分钟
平常经常会求一段时间内的每一天统计数据,或者每一时点的统计数据.但是mysql本身是没有直接获取时点列表的函数或表.下面是自己用到的一些方法,利用临时变量和一个已存在的比较多数据(这个需要根据实际情况 ...
- Easy DataGrid 实现动态列、行
Easy DataGrid 实现动态列.行 前端代码: <title>展示销售的实时数据</title> <script type="text/javascri ...
- iOS字典转模型MJExtension使用
如果项目是纯OC的建议使用,MJExtension是一套字典和模型之间互相转换的超轻量级框架,可以轻松完成: 字典(JSON) --> 模型(Model) 模型(Model) --> 字典 ...
- gitlab和github一起使用
还是在转我笔记上的内容, 也算备份 参考(https://segmentfault.com/a/1190000002994742) 可以对比着看, 我记得参考里面有个点没有说详细, 我把自己的流程记下 ...
- 解决Ubuntu手动安装vim后无法正常…
首先声明这个问题很坑爹~ 问题描述:下载了vim7.3版本的源码,在虚拟机里面的ubuntu12中手动安装成功后.在使用vim编辑文档时,进入编辑模式出现如下现象:1.使用方向键会打印出"A ...
- MongoDB3.4安装配置以及与Robomongo1.1的连接——解决Authentication Failed导致的不能连接问题
本文环境:win10(64)+MongoDB(3.4.5)+Robomongo(1.1) 目录: MongoDB的安装 MongoDB的配置 Robomongo的安装以及与MongoDB的连接 一些新 ...