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

  “贪心+暴力,从近至远依次枚举可以到达的钓鱼地点,用总时间减去中途消耗的时间,这样就可以将其当成在各个钓鱼地点之间随意转移(实际题目中给出是单方向前行的),然后在已到达的最远的钓鱼地点之内的所有钓鱼地点上按每次能钓到的鱼的最大值做贪心,若时间用不完,则剩余时间加到第一个钓鱼地点上。注意,钓鱼地点最初的钓鱼值可能为零。”

 #include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define MAXN 30 struct Lake
{
int id, f;
bool operator < (const Lake& l) const
{
if (f != l.f) return f < l.f;
else return id > l.id;
}
}; int f[MAXN], d[MAXN], t[MAXN], fish[MAXN], res[MAXN]; int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int n;
bool first = true;
while (scanf("%d", &n) && n)
{
int h;
scanf("%d", &h);
for (int i = ; i < n; i++)
scanf("%d", &f[i]);
for (int i = ; i < n; i++)
scanf("%d", &d[i]);
t[] = ;
for (int i = ; i < n; i++)
{
scanf("%d", &t[i]);
t[i] += t[i-];
}
int ans = -;
for (int i = ; i < n; i++) // the last lake arrived
{
int time = h * ;
if (t[i] > time) break;
time -= t[i];
priority_queue<Lake> q;
Lake tmp;
for (int j = ; j <= i; j++)
if (f[j])
q.push( (Lake){j, f[j]} );
memset(fish, , sizeof(fish));
int sum = ;
while (!q.empty() && time > )
{
tmp = q.top();
q.pop();
sum += tmp.f;
int id = tmp.id;
fish[id]++;
time--;
tmp.f -= d[id];
if (tmp.f > ) q.push(tmp);
}
fish[] += time;
if (sum > ans)
{
ans = sum;
memcpy(res, fish, sizeof(fish));
}
}
if (first) first = false;
else printf("\n");
for (int i = ; i < n; i++)
printf("%d%s", res[i]*, (i==n-) ? "\n" : ", ");
printf("Number of fish expected: %d\n", ans);
}
return ;
}

UVa 757 - Gone Fishing的更多相关文章

  1. uva 757

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

  2. <算法竞赛入门经典> 第8章 贪心+递归+分治总结

    虽然都是算法基础,不过做了之后还是感觉有长进的,前期基础不打好后面学得很艰难的,现在才慢慢明白这个道理. 闲话少说,上VOJ上的专题训练吧:http://acm.hust.edu.cn/vjudge/ ...

  3. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  4. UVA 816 - Abbott&#39;s Revenge(BFS)

    UVA 816 - Abbott's Revenge option=com_onlinejudge&Itemid=8&page=show_problem&category=59 ...

  5. UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据

    题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...

  6. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  7. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  8. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  9. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

随机推荐

  1. Apache的安装

    Apache的安装: 注:本例只截取需要注意的截图,其它默认则不显示. 1.       服务器信息可以按照默认配置,如果服务器的80端口没被其他服务器程序占据.可选“for All Users,on ...

  2. BootStrap详解之(二)

    六.内容 Bootstrap 将全局 font-size 设置为 14px,line-height 设置为 1.428 中心内容 .lead 将字体大小.加粗.行高修改 (无卵高深用) 标记 mark ...

  3. English--Computer System

    A: Hey, Bill, Can you tell what's wrong with my computer? I can't move the mouse, I can's user the k ...

  4. Linux 排除问题的前5分钟

    尽可能搞清楚问题的前因后果 不要一下子就扎到服务器前面,你需要先搞明白这台服务器有多少已知的情况,还有故障的具体情况,不然你很有可能是在无的放矢   必须要搞清楚的问题: 故障的表现是什么?无响应?报 ...

  5. 风格一致的backItem在项目中怎样设置

    在相应的navigationController中重写- (void)pushViewController:(UIViewController *)viewController animated:(B ...

  6. Smarty模版

    smarty.inc.php <?php //创建一个实际路径 define('ROOT_PATH',dirname(__FILE__)); //引入Smarty require ROOT_PA ...

  7. Rails (堆栈)<数据结构>

    题意:<看图片> 解题思路:栈的简单应用: #include<iostream> #include<stack> #include<algorithm> ...

  8. PHP聊天室开源系统workerman-chat

    PHP聊天室开源系统workerman-chat (2015-01-23 09:07:50) 转载▼ http://www.workerman.net/ http://www.workerman.ne ...

  9. Intellij Idea搭建java web项目(问题总结)

    这两天突发奇想下载了Intellij Idea,准备体验下这个传说中很强大IDE.工具下载就不多说了,网上一搜便知,博主是直接从Intellij官网下载的最新完整版,可惜的是只能使用30天,不过也差不 ...

  10. Bluez SPP实现代码分析(转)

    源:http://blog.csdn.net/walkingman321/article/details/7218705 本文分析蓝牙协议栈中蓝牙转串口(SPP)部分的实现. 1.  基本概念 Blu ...