题意:有个人要去湖里钓鱼,总共有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. PHP 多维数组排序 函数怎么保持数字键不被重新索引

    /** * 根据数组中的某个键值大小进行排序,仅支持二维数组 * * @param array $array 排序数组 * @param string $key 键值 * @param bool $a ...

  2. 约瑟夫斯问题-java版数组解法和链表解法

    10个人围成一圈,从1到10编号,从1开始数,数到3或3的倍数的位置,则该位置的人出局,求最后剩下哪一个号? 数组解法: 数组存放数组:a[10]存在1到10编号人 数组遍历到尾部又从头遍历:遍历数组 ...

  3. C# Cookie方法

    //写入 protected void Button1_Click(object sender, EventArgs e) { HttpCookie cookie=new HttpCookie(&qu ...

  4. Ubuntu使用总结二

    Ubuntu使用 - 1.ubuntu怎么切换到root用户,切换到root账号方法 ubuntu怎么切换到root用户,我们都知道使用su root命令,去切换到root权限,此时会提示输入密码, ...

  5. IPFS 探索

    IPFS 探索 比特币当前是用于存金融交易数据,有leveldb 存关键小的交易数据.那么我们的文件,譬如一个网站里面的static file 怎么办? IPFS(InterPlanetary Fil ...

  6. 18.13 Uboot分析与移植

    18.13.1 使用JLink烧写Nor Flash JLink只支持烧写NOR Flash,不支持烧写Nand Flash. 1.准备工作:JLink的USB口接到电脑上,JLink的JTAG口用排 ...

  7. shell脚本,如果文件中的第一列有相同的,就把相同的那些行的其他字段相加

    命令:awk '{a[$1]+=$2}{b[$1]+=$3}END{for(i in a){print i,a[i],b[i]}}'

  8. [ZZ] 深度学习三巨头之一来清华演讲了,你只需要知道这7点

    深度学习三巨头之一来清华演讲了,你只需要知道这7点 http://wemedia.ifeng.com/10939074/wemedia.shtml Yann LeCun还提到了一项FAIR开发的,用于 ...

  9. 如何去maven仓库下载jar包

    Maven仓库地址 : http://search.maven.org/ https://mvnrepository.com/ 或者你直接百度搜索 : maven仓库 第一个就是 我现在想下载myba ...

  10. 【C++】static关键字的总结

    转自 https://www.cnblogs.com/BeyondAnyTime/p/2542315.html C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的s ...