题意分析

题意:题目给出n条鱼,以及捕一条鱼所用的时间k,并给出煮每一条鱼的时间,问抓完并煮完所有鱼的最短时间。

附题目链接

思路

1.捕第一条鱼的时间是不可避免的,煮每条鱼的时间也是不可避免的,这些都要算上。

2.可以优化的是煮鱼的时间,在时间允许的范围内可进行捕其他鱼。当然煮鱼的时间也许不够捕其他鱼,这就需要增加额外的时间。

3.设在煮每条鱼煮的时间内抓的最多的鱼数为cnt,捕鱼的时间为cost,将每次额外增加的时间存储在一个数组中,记为fre[ ]。

4.更多详细信息在代码中给出。

AC代码

/*贪心*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = int(1e5+10);
int T, n, k;
int cnt; //在煮鱼期间最多能钓上来的鱼数
int t[maxn], fre[maxn];
LL cost;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &k);
cost = k; //捕第一条鱼的时间不可避免
cnt = 0;
memset(t, 0, sizeof(t));
memset(fre, 0, sizeof(fre));
for(int i = 0; i < n; i++)
{
scanf("%lld", &t[i]);
cost += t[i]; //煮鱼的时间不可避免
cnt += t[i] / k;
fre[i] = k - t[i] % k; //k - 每次煮鱼的时间所剩余的可利用时间 = 多投入的时间
}
if(cnt < n - 1)
{
sort(fre, fre + n);
for(int i = 0; i < n - 1 - cnt; i++) //贪心思想,从小往大加
cost += fre[i];
}
printf("%lld\n", cost);
}
}

参考博客:http://morecoder.com/article/1265379.html

【Fishing Master HDU - 6709 】【贪心】的更多相关文章

  1. Fishing Master HDU - 6709

    题目链接:https://vjudge.net/problem/HDU-6709 题意:给出n条鱼的抓捕时间k和煮鱼时间a[i],你要在最短时间把所有鱼都煮了.(注意你只有一口锅) 思路:首先我们必须 ...

  2. [贪心,dp] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 Fishing Master (Problem - 6709)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6709 Fishing Master Time Limit: 2000/1000 MS (Java/Othe ...

  3. Fishing Master (思维+贪心)

    题目网站:http://acm.hdu.edu.cn/showproblem.php?pid=6709 Problem Description Heard that eom is a fishing ...

  4. HDU 6709“Fishing Master”(贪心+优先级队列)

    传送门 •参考资料 [1]:2019CCPC网络选拔赛 H.Fishing Master(思维+贪心) •题意 池塘里有 n 条鱼,捕捉一条鱼需要花费固定的 k 时间: 你有一个锅,每次只能煮一条鱼, ...

  5. HDU-6709 Fishing Master

    Description Heard that eom is a fishing MASTER, you want to acknowledge him as your mentor. As every ...

  6. Hdu 5289-Assignment 贪心,ST表

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...

  7. hdu 4803 贪心/思维题

    http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么?  G++  AC  C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...

  8. hdu 1735(贪心) 统计字数

    戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意 ...

  9. hdu 4974 贪心

    http://acm.hdu.edu.cn/showproblem.php?pid=4974 n个人进行选秀,有一个人做裁判,每次有两人进行对决,裁判可以选择为两人打分,可以同时加上1分,或者单独为一 ...

随机推荐

  1. import tensorflow 报错

    >>> import tensorflowe:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py:36: Future ...

  2. dij模板

    #include<cstdio> #include<vector> #include<queue> using namespace std; struct edge ...

  3. 网页学习:day1

    初始准备: Write some function Write a titie Write a article Write some button Button function写法: functio ...

  4. js方法总结,不断更新...

    1. 返回<li> 元素父节点: document.getElementById("item1").parentNode; 2.   

  5. HashMap源码__tableSizeFor方法解析

    tableSizeFor(int cap)方法返回不小于指定参数cap的最小2的整数次幂,具体是怎么实现的呢?看源码! /** * Returns a power of two size for th ...

  6. [剑指offer] 53. 表达数值的字符串

    题目描述 请实现一个函数用来判断字符串是否表示数值(包括整数和小数).例如,字符串"+100","5e2","-123","3.1 ...

  7. NPOI 日期类型的判断

    NPOI目前我用到有两套类,一套是为了读写XLS:一套是读写XLSX 在读取文件时大都会判断单元格类型,方式大同小异,只有日期类型不同. 默认日期类型的单元格在NPOI都认为是数值类型(CellTyp ...

  8. 转载——Asp.Net MVC+EF+三层架构的完整搭建过程

    转载http://www.cnblogs.com/zzqvq/p/5816091.html Asp.Net MVC+EF+三层架构的完整搭建过程 架构图: 使用的数据库: 一张公司的员工信息表,测试数 ...

  9. GitLab-CI 来自动创建 Docker 镜像

    1.what is gitlab-ci docker image CI/CD 自动化集成,自动化部署.简单的说就是把代码提交到gitlab管理的同时部署到指定的server,打成docker imag ...

  10. springboot+kafka+邮件发送(最佳实践)

    导读 集成spring-kafka,生产者生产邮件message,消费者负责发送 引入线程池,多线程发送消息 多邮件服务器配置 定时任务生产消息:计划邮件发送 实现过程 导入依赖 <proper ...