题意:有个人要去湖里钓鱼,总共有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. 第二章代替netcat连接无响应

    按照书上的代码手打到电脑上以后,在两个终端输入了./bhnet.py -l -p 9999 -c和./bhnet.py -t localhost -p 9999之后发现没什么反映,所以又用nmap 1 ...

  2. p132程序代码解析

    1.  long before = System.currentTimeMillis(); ...... long after = System.currentTimeMillis(); 解析:该两句 ...

  3. Spock - Document -04- Interaction Based Testing

    Interaction Based Testing Peter Niederwieser, The Spock Framework TeamVersion 1.1 Interaction-based ...

  4. 总结描述用户和组管理类命令的使用方法,系统用户相关信息,取出主机IP地址

    1.列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可. [root@db146 ~]# who|cut -f1 -d' ' |sort -u root 2.取出最后 ...

  5. CF285D.Permutation Sum

    想了很久觉得自己做法肯定T啊,就算是CF机子的3s时限,但我毕竟是 O ( C(15,7)*7!*log ) .... 果然在n=15的点T了...贱兮兮地特判了15过掉了,结果发现题解说就是打表.. ...

  6. 听说https更安全

    0--介绍: 现在人们对网络的依赖越来越重,那么对于网络安全的要求也越来越高,传统的http协议实现了网络中的快速传输,完整传输,保证了信息的完整性,但是对于网络的安全性却没有那么强,很容易被人劫持, ...

  7. Go语言极速入门手册.go

    Github: https://github.com/coderzh/CodeTips /* gotips_test.go: Golang速学速查速用代码手册 Source: github.com/c ...

  8. 芯灵思Sinlinx A33开发板boa与CGI移植

    开发平台 * 芯灵思SinlinxA33开发板 淘宝店铺: https://sinlinx.taobao.com/ 嵌入式linux 开发板交流 641395230 在嵌入式设备的管理与交互中,基于W ...

  9. 剑指offer 8.递归和循环 跳台阶

    题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果).   解题思路一: a.如果两种跳法,1阶或者2阶,那么假定第一次跳的是 ...

  10. httpd2.4.6配置文件解释说明

    本文httpd版本为:2.4.6 ServerRoot 先来看一下httpd.conf配置文件中的ServerRoot默认定义: # cat /etc/httpd/conf/httpd.conf |e ...