ZOJ 3778 Talented Chef 模拟 [ 祝愿明天省赛一帆风顺, ZJSU_Bloom WILL WIN : )
这题的意思是给你 n 道菜,第 i 道菜需要 Ai 步才能完成
每次你能对 m 道菜分别完成一步,请问最少需要几次?
这题暴力写肯定是不行的,去年省赛的时候就是没写出来这题,今天再把思路理一理吧。
首先我们需要明确的是
1. n <= m 的时候, 那么答案显而易见,就是 Max (A[i])
2. n > m
①此时我们不难发现这个现象,如果 sum (A[i]) 能被 m 整除,那么我们可能恰恰只需要 (sum / m) 次即可完成
一个例子: n = 3, m = 2
a[1] = 1, a[2] = 2, a[3] = 3
②如果,sum (A[i]) 不能被 m 整除,那么只需要在 ① 的基础上加1即可
当然,这里不能忘了,在答案输出的时候,要保证答案 >= Max(A[i]), 否则会出现对一个 A[i] 多次减法操作
贴上 Source Code:
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <algorithm> using namespace std; int a[];
int n, m; int main (){
int i, j, k, u, v, t; cin >> t;
while (t--) {
cin >> n >> m;
int sum = ;
int MAX = ;
for (i = ; i < n; ++i){
cin >> a[i];
sum += a[i];
MAX = max (MAX, a[i]);
} if (n <= m) {
cout << MAX << endl;
continue;
} int cur = sum / m;
if (sum % m != ) ++cur; cur = max(cur, MAX); cout << cur << endl;
} return ;
}
ZOJ 3778 Talented Chef 模拟 [ 祝愿明天省赛一帆风顺, ZJSU_Bloom WILL WIN : )的更多相关文章
- 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 Chief
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3778 题目 某人做菜很厉害,一分钟能同时完成最多m个菜的一道工序,输入菜的 ...
- 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 ...
- Talented Chef(简单题,被我想的太复杂了,用复杂的方法当然会超时咯,由此可见,并非所有题都是想的越多越好)
Description As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the ...
- 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. ...
- ZOJ 3778 C - Talented Chef 水题
LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3778 题意:有n道菜,每道菜需要\(a_i\)道工序,有m个锅可 ...
随机推荐
- python初探-collections容器数据类型
collections容器数据类型是对基本数据类型的补充,简单介绍下计数器.有序字典.默认字典.可命名元祖.队列. 计数器(Counter) Counter是对字典类型的补充,用于追踪值得出现次数 c ...
- [LeetCode]题解(python):072-Edit Distance
题目来源: https://leetcode.com/problems/edit-distance/ 题意分析: word1最少通过多少步可以变成word2.word1只能进行一下的操作.a)插入一个 ...
- chroot命令
CHROOT就是Change Root,也就是改变程序执行时所参考的根目录位置.通过chroot机制来更改某个进程所能看到的根目录,即将某进程限制在指定目录中,保证该进程只能对该目录及其子目录的文件有 ...
- c语言(3)--运算符&表达式&语句
计算机的本职工作是进行一系列的运算,C语言为不同的运算提供了不同的运算符! 1.那些运算符们 .基本运算符 算术运算符:+ - * / % ++ -- 赋值运算符:= 逗号运算符:, 关系运算符:& ...
- 转: vim简明教程
vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会对这个编辑器失去兴趣的.下面的文章翻译自<Learn Vim Progress ...
- HDU 2501 Tiling_easy version
递推式:f[n]=2*f[n-2]+f[n-1] #include <cstdio> #include <iostream> using namespace std; ]; i ...
- fedora 安装pylab 并简单绘制三角函数
pylab 由 三个部分组成:scipy, matplotlab, numpy三部分组成,安装时需要分别安装这三部分,在fedora中,可以使用命令: sudo dnf install python- ...
- 20140603 对error.c 用于分析源代码
20140603 对error.c 用于分析源代码 继续看error.c该功能 买家现在将自己的代码和数据汇编例如,下面的: 1.#include <stdio.h> 2 #inc ...
- wpf全局异常
在App.xaml文件中 添加DispatcherUnhandledExceptionEventArgs 新增对应事件
- Session、SessionId和Cookie的关系
Session是保存在服务器中的,SessionId是保存在Cookie中的. 当用户·登录时候,系统会将"用户名"和"密码"保存到Session中,系统会给每 ...