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 <= NM <= 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(简单题,被我想的太复杂了,用复杂的方法当然会超时咯,由此可见,并非所有题都是想的越多越好)的更多相关文章

  1. 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. ...

  2. 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. ...

  3. ZOJ 3778:Talented Chef(贪心?思维)

    Talented Chef Time Limit: 2 Seconds Memory Limit: 65536 KB As we all know, Coach Gao is a talented c ...

  4. Java实现UVA10131越大越聪明(蓝桥杯每周一题)

    10131越大越聪明(蓝桥杯每周一题) [问题描述] 一些人认为,大象的体型越大,脑子越聪明.为了反驳这一错误观点,你想要分析一组大象的数据,找出尽量 多的大象组成一个体重严格递增但 IQ 严格递减的 ...

  5. Maven系列第8篇:你的maven项目构建太慢了,我实在看不下去,带你一起磨刀!!多数使用maven的人都经常想要的一种功能,但是大多数人都不知道如何使用!!!

    maven系列目标:从入门开始开始掌握一个高级开发所需要的maven技能. 这是maven系列第8篇. 整个maven系列的内容前后是有依赖的,如果之前没有接触过maven,建议从第一篇看起,本文尾部 ...

  6. MouseMoveEvent为了不太耗资源在默认状态下是要鼠标按下才能捕捉到。要想鼠标不按下时的移动也能捕捉到,需要setMouseTracking(true)

    最近用Qt软件界面,需要用到mouseMoveEvent,研究了下,发现些问题,分享一下. 在Qt中要捕捉鼠标移动事件需要重写MouseMoveEvent,但是MouseMoveEvent为了不太耗资 ...

  7. ZOJ 3778 Talented Chef(找规律,模拟计算,11届ACM省赛,简单)

    题目链接 2014年浙江省赛C题,当时觉得难,现在想想这题真水.. 找规律: 若   最大的那个步骤数*m-总和>=0,那么答案就是 最大的那个步骤数 . 否则  就要另加上不够的数量,具体看代 ...

  8. zoj 3778 Talented Chef(思维题)

    题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...

  9. ZOJ 3778 C - Talented Chef 水题

    LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3778 题意:有n道菜,每道菜需要\(a_i\)道工序,有m个锅可 ...

随机推荐

  1. 【整理】Object-C中的属性(Property)的Setter:assign,copy,retain,weak,strong之间的区别和联系

    iOS编程过程中,经常看到一些属性前面有些修饰符,比如copy,retain等. 这些关键字,是Object-C语言中,对于Property的setter. Mac官网: The Objective- ...

  2. C++时间获取

    http://net.pku.edu.cn/~yhf/linux_c/function/04.html   asctime(将时间和日期以字符串格式表示) 相关函数 time,ctime,gmtime ...

  3. JSP内置对象----response

    response 对象   当客户访问一个服务器的页面时,会提交一个HTTP 请求,服务器收到请求时,返回HTTP 响应.request 对象获取客户请求提交的信息,  与request对象相对应的对 ...

  4. MYSQL存储过程事务列子

    CREATE DEFINER=`root`@`localhost` PROCEDURE `createBusiness`(parameter1 int) BEGIN #Routine body goe ...

  5. ASP.NET MVC5 学习笔记-4 OWIN和Katana

    1. Owin OWIN全名:Open Web Interface for .NET. 它是一个说明,而非一个框架,该声明用来实现Web服务器和框架的松耦合.它提供了模块化.轻量级和便携的设计.类似N ...

  6. MultiView空间例子

    CSS代码: body { font-size:11pt; font-family:宋体; } .mainTitle { font-size:11pt; font-weight:bold; font- ...

  7. HDU 3466 Proud Merchants

    题目大意:现在给出商品,有三个参数,记为pi,qi,vi,vi是商品的在你心里价值,pi是商品的价格,qi是你要买商品的时候至少需要的钱然后求可得的最大价值. 单词积累:Merchants 商人  t ...

  8. Linux通过网卡驱动程序和版本号的信息

    检查卡制造商和信号 查看基本信息:lspci 查看详情:lspci -vvv   # 3小作文v 查看卡信息:lspci | grep Ethernet 查看网卡驱动 查看网卡驱动信息:lspci - ...

  9. NGUI 按钮音效问题

    昨天给NGUI的按钮添加音效时,刚开始是自己新建空对象绑定声音的,后来发现NGUI按钮携带button sound组件,直接将音效拖入即可,不用写一行代码,非常简单.但是后来发现添加相同的音效有的按钮 ...

  10. 补全aaz288 可能有问题的过程 P_COMPL_AAZ288

    补全aaz288 可能有问题的过程: /* add by weiyongle 20160623 失地农民补足aaz288,针对早期导出的数据(只适用于江安县) 经测试:江安县 江安县个体劳动者 这个单 ...