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,打表的姿势不对. ...
随机推荐
- springmvc学习笔记--Interceptor机制和实践
前言: Spring的AOP理念, 以及j2ee中责任链(过滤器链)的设计模式, 确实深入人心, 处处可以看到它的身影. 这次借项目空闲, 来总结一下SpringMVC的Interceptor机制, ...
- [读书笔记]OSGI-灵活的类加载器架构
以下内容来自周志明的<深入理解Java虚拟机>. 学习JEE规范,去看JBoss源码:学习类加载器,就去看OSGI源码. OSGI,即Open Service Gateway Initia ...
- cocos2d 保存最近登陆多个账号最多一个月
用的是一个单例来管理 ,数据是存在本地的xml文件里的格式如下 <?xml version="1.0" encoding = "utf-8" ?> ...
- TYVJ 1074 武士风度的牛
easy BFS 注意输入是反的就OK了 #include <cstdio> #include <iostream> #include <queue> using ...
- hdu2191 悼念512汶川大地震 ——多重背包
link:http://acm.hdu.edu.cn/showproblem.php?pid=2191 最简单的那种 #include <iostream> #include <cs ...
- |原创|unity 4.3 2D功能SpriteRenderer修改颜色的方法
4.3增加了不少2D功能,然后实在没有找到有人分享,在国外查资料研究一下午然后给个简单的教程 ===================================================== ...
- 处理畅捷通的T+ 12.0版,web服务无故自动停止的问题
用了几个月的畅捷通T+ 12.0版,一直都挺正常,但最近这两周,出现了好几次web服务自动停止的情况,今天抽空仔细看了Windows的日志,发现在半夜2点左右,TPlusProWebService12 ...
- BulkCopy频繁执行产生的性能问题
问题现象: 完整的SQL脚本如下: from all_cons_columns acc, all_constraints ac where acc.owner = ac.owner and acc.c ...
- CentOS 7 时间同步
在做这个之前需要先搭建yum http://www.cnblogs.com/jw31/p/5955852.html 在做之前我们需要先安装ntp服务 yum install ntp -y vi /et ...
- 【uTenux实验】写在开始实验之前
1.使用的uTenux内核代码:http://www.uloong.cc/cn/download/uTenux_V1.6.00r180.zip 2.uTenux的特性: 1.微内核 2.开放源码.完 ...