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,打表的姿势不对. ...
随机推荐
- java.lang.ClassCastException: java.lang.String cannot be cast to com.jy.hfims.domain 映射实体类型错误
今天在做 excel导出的时候,出现了一个问题"java.lang.ClassCastException: java.lang.String cannot be cast to com.do ...
- kernel/panic.c
/* * linux/kernel/panic.c * * Copyright (C) 1991, 1992 Linus Torvalds */ /* * This function is us ...
- Python 爬虫学习 网页图片下载
使用正则表达式匹配 # coding:utf-8 import re import urllib def get_content(url): """ Evilxr, &q ...
- truncate有外键约束的表,报ORA-02266处理。
问题描述:当父表有子表的外键约束时,无法直接truncate父表.报ORA-02266: unique/primary keys in table referenced by enabled fore ...
- Scrollview 嵌套 RecyclerView 及在Android 5.1版本滑动时 惯性消失问题
标签:scrollview android 滑动 嵌套 scrollview 嵌套recyclerview 时,recyclerview不显示,这就需要我们自己计算recyclerview ...
- Java基础之-ExecutorService
翻译javadoc系列文章之:ExecutorService /** * An {@link Executor} that provides methods to manage termination ...
- mysql 主从 重新同步
mysql 主从同步一担出了问题之后,就会导致从库上的数据和主库不一样了.所以需要生新同步数据. 1.登录主库服务器,进入mysql,命令为:mysql -uroot -ppassword 2.执行: ...
- 第一节:简单的请求(Requests)和响应(Responses)
目录 创建项目 开发服务器 创建名称为Polls的应用 编写你的第一个视图 创建项目 在命令行中,使用cd命令进入到你想要存储你的项目的目录,然后运行下面的命令: $ django-admin sta ...
- CAD的API们
AutoCAD有4种API,.net,lisp,activex和ObjectARX(C++).它们都是用来给cad写插件什么的,依赖cad运行. 另有一个RealDWG SDK,这是用来读写dwg或d ...
- LVS+Keepalived负载均衡配置
简介 lvs一般是和keepalived一起组合使用的,虽然也可以单独使用lvs,但配置比较繁琐,且可用性也没有前者高. lvs和keepalived组合使用后,配置lvs的VIP和负载均衡就都在ke ...