ZOJ3778--一道水题
Description
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个菜,每个菜有几个步骤,煮菜的每分钟,厨师能够最多同时煮m个菜,完成选择菜的一步,(在一分钟哦)
这里求的是做菜的最短时间是多少。
我们想想如果m>n,那么他可以同时做所有菜的步骤,最短时间肯定是煮最长的那个菜的时间,如果m<n,那么我们可以这样想,厨师每分钟都同时煮m个菜,那么总的步奏需要多少次,也就是多少分钟了,那我们算出总步骤除以M,如果这个数比最多那个步骤小,就说明结果肯定是最多步骤那道菜,如果比最多那个步骤大,那就是这个数。
#include<iostream>
#include<string>
using namespace std;
int main(){
int a,n,m;
cin>>a;
while(a--){
cin>>n>>m;
int p=n;
int maxn=;
int b[];
int sum=;
for(p=n;p>;p--){
cin>>b[p];
sum=sum+b[p];
if (maxn<b[p])
{maxn =b[p];}
}
if(m>=n){cout<<maxn<<endl;}
else
{p=sum/m;
if (sum%m>)
{p=p+;}
if (p<maxn){cout<<maxn<<endl;}
else {cout<<p<<endl;} }
}
return ;
}
这里还要注意,如果不能整除呢,就还需要加一分钟,其实我不懂的就是,这里。记下吧
ZOJ3778--一道水题的更多相关文章
- ny525 一道水题
一道水题时间限制:1000 ms | 内存限制:65535 KB 难度:2描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他吗? ...
- NYOJ-525一道水题思路及详解
一道水题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他 ...
- LibreOJ #6165. 一道水题
二次联通门 : LibreOJ #6165. 一道水题 /* LibreOJ #6165. 一道水题 欧拉线性筛 其实题意就是求区间[1, n]所有数的最小公倍数 那么答案就是所有质因子最大幂次的乘积 ...
- [ Luogu 4626 ] 一道水题 II
\(\\\) \(Description\) 求一个能被\([1,n]\) 内所有数整除的最小数字,并对 \(100000007\) 取模 \(N\in [1,10^8]\) \(\\\) \(Sol ...
- [Luogu] P4626 一道水题 II
---恢复内容开始--- 题目描述 一天,szb 在上学的路上遇到了灰太狼. 灰太狼:帮我们做出这道题就放了你. szb:什么题? 灰太狼:求一个能被 [1,n] 内所有数整除的最小数字,并对 100 ...
- 2018焦作网络赛 - Poor God Water 一道水题的教训
本题算是签到题,但由于赛中花费了过多的时间去滴吧格,造成了不必要的浪费以及智商掉线,所以有必要记录一下坑点 题意:方格从1到n,每一格mjl可以选择吃鱼/巧克力/鸡腿,求走到n格时满足 1.每三格不可 ...
- 牛客小白月赛9H论如何出一道水题(两个连续自然数互质)
题面 记录一下...连续得两个自然数互质,这题再特判一下1的情况 #include<bits/stdc++.h> using namespace std; int main() { lon ...
- UPC OJ 一道水题 STL
Problem C: 字符串游戏 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 10 Solved: 3 [Submit][Status][Web ...
- 又是一道水题 hdu背包
Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负) ...
- 【我与一道水题的抗争之路】 哈理工2323 Emirp(反素数)
题目: http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2323 1,打表的姿势不对. ...
随机推荐
- 关于CSS的那些事?
关于CSS的那些事? 它有精准定位与排版,使得网页布局.信息排版一目了然:它有多姿多彩的样式属性,使得网页中各元素千变万化:它有神奇的渲染天赋,使得网页有了如诗如画.别具一格的魅力.你知道它了吗?没错 ...
- 我用工具怎么连接不上mysql数据库的? MySql access denied for user错误
MySql access denied for user错误 方法/步骤 MySql远程连接时的"access denied for user **@**"错误,搞的我很头大, ...
- C#项目实例中读取并修改App.config文件
C#项目是指一系列独特的.复杂的并相互关联的活动,这些活动有着一个明确的目标或目的,必须在特定的时间.预算.资源限定内,依据规范完成.项目参数包括项目范围.质量.成本.时间.资源. 1. 向C#项目实 ...
- Android 扫一扫----ZXing 的使用
1. 首先现在ZXing的lib 2. 在Android Studio集成ZXing. public void scan(View view){ startActivityForResult(new ...
- [java] java解析txt文件
/** * 读取txt文件内容封装为map返回 * @param filePath * @return */ public static String readTxt(String filePath) ...
- CSS3 旋转代码备忘
.Aclose { -webkit-transition-property: all; -webkit-transition-duration: .3s; -moz-transition-proper ...
- springfox.documentation.spi.DocumentationType配置示例
Java Code Examples for springfox.documentation.spi.DocumentationType The following are top voted exa ...
- reorderList使用
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" /> ...
- Parquet文件结构笔记
Parquet是面向分析型业务的列式存储格式,由Twitter和Cloudera合作开发,2015年5月从Apache的孵化器里毕业成为Apache顶级项目,那么这里就总结下Parquet数据结构到底 ...
- vim 学习日志(4):多窗口使用技巧
原文地址: http://blog.csdn.net/devil_2009/article/details/7006113 vim多窗口使用技巧 1.打开多个窗口打开多个窗口的命令以下几个:横向切割窗 ...