题意:有个人要去湖里钓鱼,总共有N个湖,排成一个序列,用字母P表示湖,从湖pi 到 pi+1(下一个湖)需要ti个五分钟.

并且,每个湖里可钓出来的鱼每过五分钟就减少di.如果产出的鱼小于等于di.那么下个五分钟这个湖再也不会产出鱼.

问:使得总的钓出鱼数目最大和每个湖花费的对应时间,.如果鱼数目最大存在多种解,让时间尽可能花费在前面的湖上.

解法:

枚举每一个pi,划去从p0至pi的总time(总的转移时间).

这样我们就可以在任意p0-pi之间钓鱼而不用考虑time的问题.剩下的h全部花费在钓鱼上.
每次花费的五分钟都花在产出鱼数目最大的湖上.这样得到总鱼数目总是最大的.如果所有的鱼都钓完还有时间剩余.全部加在第一个湖上面.

#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<iomanip>
#include<bitset>
#include"math.h"
namespace cc
{
using std::cout;
using std::endl;
using std::cin;
using std::map;
using std::vector;
using std::string;
using std::sort;
using std::priority_queue;
using std::greater;
using std::vector;
using std::swap;
using std::stack;
using std::queue;
using std::bitset; class State
{
public: int curFish;
int d;
int time;
int index;
State() {}
State(int curFish, int d, int time, int index) :
curFish(curFish), d(d), time(time), index(index)
{ }
friend bool operator < (const State& s1, const State& s2)
{
if (s1.curFish != s2.curFish)
return s1.curFish < s2.curFish;
return s1.index > s2.index;
}
}; constexpr int N = ;
int H = ;
int n; int totalFish;
int per[N] = { };
State states[N]; priority_queue < State>q; void solve()
{
int t = ;
while (cin >> n && n)
{
if (t != )
cout << endl;
++t;
cin >> H;
H = H * ;
int f = ;
for (int i = ;i < n;i++)
{
cin >> f;
State state(f, , , i);
states[i] = state;
}
for (int i = ;i < n;i++)
{
cin >> states[i].d;
}
for (int i = ;i < n;i++)
{
cin >> states[i].time;
states[i].time = states[i].time + states[i-].time;
}
totalFish = -;
memset(per, , sizeof(per));
for (int i = ;i < n;i++)
{
while (q.empty() == false)
q.pop();
for (int k = ;k <= i;k++)
q.push(states[k]);
int h = H;
int curTotalFish = ;
int times[N] = {};
h = h - states[i].time;
while (h > )
{
State s = q.top();
q.pop();
int f = s.curFish;
if (f <= )break;
--h;
s.curFish -= s.d;
curTotalFish += f;
times[s.index]++;
q.push(s);
}
if (h > )
times[] += h;
if (curTotalFish > totalFish)
{
totalFish = curTotalFish;
memcpy(per, times, sizeof(times));
}
}
cout << per[] * ;
for (int i=;i<n;i++)
cout<<", " << per[i] * ;
cout << endl;
cout << "Number of fish expected: " << totalFish << endl;
}
}
}; int main()
{ #ifndef ONLINE_JUDGE
freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
cc::solve(); return ;
}

uva-757-贪心的更多相关文章

  1. 01_传说中的车(Fabled Rooks UVa 11134 贪心问题)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P81: 问题描述:你的任务是在n*n(1<=n<=5000)的棋盘上放n辆车,使得任意两辆车不相互攻击,且第i辆车在一个给定 ...

  2. UVA 11389(贪心问题)

    UVA 11389 Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description II  ...

  3. uva 10154 贪心+dp

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  4. uva 757

    贪心  优先队列 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> ...

  5. UVa 11389 (贪心) The Bus Driver Problem

    题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线. 给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r. 问如何分配路线才能使加班费最少. 分析: 感 ...

  6. UVa 1467 (贪心+暴力) Installations

    题意: 一共有n项服务,每项服务有安装的时间s和截止时间d.对于每项任务,如果有一项超出截止时间,惩罚值为所超出时间的长度.问如何安装才能使惩罚值最大的两个任务的惩罚值之和最小. 分析: 如果是求总惩 ...

  7. UVa 757 - Gone Fishing

    题目大意:John有h的时间可以去钓鱼,有n湖可钓鱼,以5分钟为时间单位,每个湖初始每个单位时间可钓f条鱼,每下一个时间单位数量减少d条.同时,John只能从1号湖往后走进行钓鱼,湖之间的距离需要t个 ...

  8. Party Games UVA - 1610 贪心

    题目:题目链接 思路:排序后处理到第一个不同的字符,贪心一下就可以了 AC代码: #include <iostream> #include <cstdio> #include ...

  9. UVa 1149 (贪心) Bin Packing

    首先对物品按重量从小到大排序排序. 因为每个背包最多装两个物品,所以直觉上是最轻的和最重的放一起最节省空间. 考虑最轻的物品i和最重的物品j,如果ij可以放在一个包里那就放在一起. 否则的话,j只能自 ...

  10. UVA 10037 贪心算法

    题目链接:http://acm.hust.edu.cn/vjudge/contest/122829#problem/A 题目大意:N个人夜里过河,总共只有一盏灯,每次最多过两个人,然后需要有人将灯送回 ...

随机推荐

  1. 湖南大学第十四届ACM程序设计新生杯(重现赛)I:II play with GG(博弈论||DP)

    链接:https://ac.nowcoder.com/acm/contest/338/I 来源:牛客网 题目描述 IG won the S championship and many people a ...

  2. PHP数据库连接mysql与mysqli的区别与用法

    一.mysql与mysqli的概念相关: 1.mysql与mysqli都是php方面的函数集,与mysql数据库关联不大. 2.在php5版本之前,一般是用php的mysql函数去驱动mysql数据库 ...

  3. 在Ubuntu下安装lrzsz

    目录 自动安装 手动安装 下载 解压 安装 创建连接 在Ubuntu 14.04x64下安装lrzsz 自动安装 在终端中,输入命令 sudo apt-get install lrzsz 由于一些原因 ...

  4. eclipse运行无错的ssm项目,迁移到idea出错

    我的报错信息为mapper绑定相关错误,是因为idea在构建项目时,target/classes目录下不存在mapper.xml文件 解决方法: <!-- 在maven中添加以下配置,它的父标签 ...

  5. 学习笔记TF054:TFLearn、Keras

    元框架(metaframework). TFLearn.模块化深度学习框架,更高级API,快速实验,完全透明兼容. TFLearn实现AlexNet.https://github.com/tflear ...

  6. github上传代码返回403错误

    报错代码: ****************   表示上传的项目地址 remote: Permission to Jayson00/camera.git denied to Minelinkinpar ...

  7. python中的time模块和datetime模块

    >>> import time>>> time.time()1511330865.656656>>> time.localtime(time.ti ...

  8. [小程序]_ELVE_小程序开发(1)

    最近在自学小程序,但是网上大部分重点都放在了界面的设计上,涉及到后端的很少,博主索性写点博客总结一下. #0X01  node.js环境搭建 不同于其他教程,本系列先重点介绍服务器端,后续再介绍客户端 ...

  9. java单例设计模式总结及举例

    * 设计模式:前人总结出来的经验,被后人直接拿来使用. * 单例设计模式:一个类只允许有一个对象,将这个对象作为一个全局的访问点,提供出去供大家使用. * 分析: * 1.用户只能有一个对象 * 2. ...

  10. 原生JS实现选中的radio变为未选中

    需求如下,radio已经选中,再点击,取消选中状态. 效果如链接:演示地址 直接上代码: <!DOCTYPE html> <html> <head> <met ...