Talented Chef(简单题,被我想的太复杂了,用复杂的方法当然会超时咯,由此可见,并非所有题都是想的越多越好)
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 source这道题比赛的时时候总是超时,因为每做一次菜我都把剩余的菜的步数排序,让他从步数最多的开始做,
这样总共可能做40000道菜,即使我用的快排,复杂度也是特别高的 第一行输入测试案例数t
第二行输入厨师一共要做的菜数,和同一分钟能同时做的菜数
求厨师做完这些菜所花的最短时间 我的超时代码如下
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int t, d[];
scanf("%d",&t);
while(t--)
{
int n, m, cnt = ;
scanf("%d%d",&n, &m);
memset(d, , sizeof(d));
for(int i = ; i < n; i++)
scanf("%d", &d[i]);
sort(d, d + n, cmp);
while(d[] != )
{
for(int i = ; d[i] != && i < m; i++)
{
d[i]--;
}
sort(d, d+n, cmp);
cnt++;
}
printf("%d\n", cnt);
}
}
上边的代码中sort函数要用到的比较函数我总是写错,记住是 return a > b;
后来发现不用这么麻烦,反正我的思想也是一刻都不让厨师闲着(每过一分钟都排序也是这个原因),能完全发挥本领就让他完全发挥本领,所以把 (所有菜的步骤数之和) / (厨师每分钟可以做的菜数) + (所有菜的步骤数之和) % (厨师每分钟最多做的菜数) 与 步骤数最多的菜的步骤数进行比较,较大的即为结果
这样简单多了,自然不会超时,原是我想多了啊,哈哈
#include <stdio.h>
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n, m, sum = , maxd = , a;
scanf("%d%d", &n, &m);
for(int i = ; i < n; i++)
{
scanf("%d", &a);
if(a > maxd)
maxd = a;
sum += a;
}
a = sum / m;
if(sum % m)
a++;
if(a > maxd)
printf("%d\n", a);
else
printf("%d\n", maxd);
}
return ;
}
Talented Chef(简单题,被我想的太复杂了,用复杂的方法当然会超时咯,由此可见,并非所有题都是想的越多越好)的更多相关文章
- 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. ...
- 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:Talented Chef(贪心?思维)
Talented Chef Time Limit: 2 Seconds Memory Limit: 65536 KB As we all know, Coach Gao is a talented c ...
- Java实现UVA10131越大越聪明(蓝桥杯每周一题)
10131越大越聪明(蓝桥杯每周一题) [问题描述] 一些人认为,大象的体型越大,脑子越聪明.为了反驳这一错误观点,你想要分析一组大象的数据,找出尽量 多的大象组成一个体重严格递增但 IQ 严格递减的 ...
- Maven系列第8篇:你的maven项目构建太慢了,我实在看不下去,带你一起磨刀!!多数使用maven的人都经常想要的一种功能,但是大多数人都不知道如何使用!!!
maven系列目标:从入门开始开始掌握一个高级开发所需要的maven技能. 这是maven系列第8篇. 整个maven系列的内容前后是有依赖的,如果之前没有接触过maven,建议从第一篇看起,本文尾部 ...
- MouseMoveEvent为了不太耗资源在默认状态下是要鼠标按下才能捕捉到。要想鼠标不按下时的移动也能捕捉到,需要setMouseTracking(true)
最近用Qt软件界面,需要用到mouseMoveEvent,研究了下,发现些问题,分享一下. 在Qt中要捕捉鼠标移动事件需要重写MouseMoveEvent,但是MouseMoveEvent为了不太耗资 ...
- ZOJ 3778 Talented Chef(找规律,模拟计算,11届ACM省赛,简单)
题目链接 2014年浙江省赛C题,当时觉得难,现在想想这题真水.. 找规律: 若 最大的那个步骤数*m-总和>=0,那么答案就是 最大的那个步骤数 . 否则 就要另加上不够的数量,具体看代 ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- ZOJ 3778 C - Talented Chef 水题
LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3778 题意:有n道菜,每道菜需要\(a_i\)道工序,有m个锅可 ...
随机推荐
- C++的常量折叠(一)
前言 前几天女票问了我一个阿里的面试题,是有关C++语言的const常量的,其实她一提出来我就知道考察的点了:肯定是const常量的内存不是分配在read-only的存储区的,const常量的内存分配 ...
- python的map()函数
map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回. 例如,对于list [1, 2 ...
- HTML+CSS笔记 CSS中级 颜色&长度值
颜色值 在网页中的颜色设置是非常重要,有字体颜色(color).背景颜色(background-color).边框颜色(border)等,设置颜色的方法也有很多种: 1.英文命令颜色 语法: p{co ...
- ***EF中的问题(复习的同学可略过)
1.当类中出现两个导航属性时,需使用额外代码说明类之间的关系. [ForeignKey("Id")] [InverseProperty("Id"]
- Eclipse运行慢
http://blog.csdn.net/chrissata/article/details/7759836 http://blog.csdn.net/heyutao007/article/detai ...
- HDU 3746 Cyclic Nacklace KMP
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3746 KMP算法—— AC代码: #include <iostream> #include ...
- Struts2 API的chm格式帮助文档制作教程
Struts2 API的chm格式帮助文档制作教程 在SSH三个框架中,Struts2的API文档是最难做的,这里所说的格式是chm格式的,chm的格式很方便,Hibernate API文档和Spri ...
- C#中字符串的处理,对象的引用及继承(Tenth day)
又进入到了新的一周,现在到总结的时间了,继续为大家总结一下今天在云和学院所学的知识. 理论: StringBuilder 和 String 的区别 String 在进行运算时(如赋值.拼接等)会 ...
- iOS推送证书p12转成pem
首先你需要导出p12格式的证书,具体操作请参考如下: 其次你就可以通过在控制台输入如下命令即可转换: openssl pkcs12 -in 你导出的p12证书 -out 你要转换的pem证书 -nod ...
- 由命名空间函数而引发思考--js中的对象赋值问题
最近没有编码任务,作为一个才毕业的小辣鸡,给的任务就是看一下公司的新系统,熟悉怎么用哪些地方是干什么的. 下午喝了两杯水,感觉有点浪.然后就开始看了下代码.发现有一个函数是这样子的. var TX = ...