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,打表的姿势不对. ...
随机推荐
- DHCP服务器安装及配置
一.什么是DHCP? DHCP (Dynamic Host Configuration protocol)动态主机设置协议,基于UDP(发送很小的数据报文,且对时效性要求较高)协议通信. 它是C/S架 ...
- CE5 中断
一.intr.h里面定义硬件中断号 #define IRQ_EINT0 0 #define IRQ_EINT1 1 #define IRQ_EINT2 2 #define IRQ_EINT3 3 #d ...
- 黑马程序员——JAVA基础之File类,递归,打印流,合并切割流
------- android培训.java培训.期待与您交流! ---------- File类 用来将文件或者文件夹封装成对象 方便对文件与文件夹的属性信息进行操作. File对象可以作为参数传递 ...
- connect VisualVM to Tomcat
https://blogs.oracle.com/jmxetc/ http://stackoverflow.com/questions/1051817/unable-to-connect-to-tom ...
- MFC 线程使用
CWinThread* m_pthread; //多线程对象 struct param//参数传递结构体 { int id; TASK t[20]; }; CNB400Dlg::CNB400Dlg( ...
- JSBinding / About 2048 sample
2048 Source 2048 source code is here: https://github.com/gabrielecirulli/2048 Play here!http://gabri ...
- supervisor使用详解
1.什么是supervisorsupervisor是用python写的一个进程管理工具,用来启动,重启,关闭进程. 2.supervisor的安装 pip install supervisor 3.s ...
- IntelliJ IDEA15导入jar包
在IDEA中导入jar包和eclipse中是不一样的,那么现在我们就来看看在IDEA中如何导入jar包. 1.点击"File"-->"Project Structu ...
- Android模拟器部署历程
由于想玩一款手机的游戏,本人手机Android系统版本太低,不能安装.所以就想在WindowS上安装一个模拟器,然后安装游戏.想法挺好.实现起来确实经历了一个坎坷的过程.为了让其他人少走弯路,本人把此 ...
- 【学】CSS3的3D动画 ——3D旋转之骰子样式的钟表(2)上
这个是3D旋转的进阶版,是一个类似与骰子的正方体.这个版本只有秒数的个位数,还没有写整个钟表,下面那个版本好好想想该怎么写 这个效果需要用到transform-style: preserve-3d. ...