题意:一个人要在n个湖中钓鱼,湖之间的路径是单向的,只能走1->2->3->...->n这一条线路,告诉你每个湖中一开始能钓到鱼的初始值,和每钓5分钟就减少的数量,以及湖之间的距离,问用h小时最多钓多少鱼。鱼的数量不会增加,而且如果不钓鱼的话鱼的数量不会减少,如果有多个答案,输出在小号的湖上花费时间最多的答案。

解法:贪心。枚举在前i个湖里钓鱼,那么走的路程就是一定的,用总时间减去走过的时间,剩下的时间每5分钟为一个单位,选鱼最多的湖钓,然后更新湖里鱼的数量。据说dp也可以做,大概想到了但是觉得好麻烦没有写……以下是我的想法……欢迎指正:可以用一个结构体dp数组,结构体里存鱼数和时间,dp[i][j]表示在前i个湖里钓鱼用了j时间时钓到的鱼数和在第i个湖用的时间,应该就可以了吧……

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
struct node
{
int f, d, id;
bool operator < (const node &tmp) const
{
if(f == tmp.f) return id > tmp.id;
else return f < tmp.f;
}
}l[30];
int sum[30];
int ans[30][30];
int main()
{
int n, h;
while(~scanf("%d", &n) && n)
{
scanf("%d", &h);
memset(sum, 0, sizeof sum);
memset(ans, 0, sizeof ans);
for(int i = 1; i <= n; i++)
{
scanf("%d", &l[i].f);
l[i].id = i;
}
for(int i = 1; i <= n; i++)
scanf("%d", &l[i].d);
for(int i = 2; i <= n; i++)
{
int x;
scanf("%d", &x);
sum[i] = sum[i - 1] + x;
}
int st = h * 12;
int maxn = -1, pos = 0;
for(int i = 1; i <= n; i++)
{
priority_queue <node> q;
for(int j = 1; j <= i; j++)
q.push(l[j]);
int res = 0;
for(int j = 0; j < st - sum[i]; j++)
{
node tmp = q.top();
q.pop();
res += tmp.f;
ans[i][tmp.id]++;
q.push((node){max(0, tmp.f - tmp.d), tmp.d, tmp.id});
}
if(res > maxn)
{
maxn = res;
pos = i;
}
}
for(int i = 1; i <= n; i++)
{
if(i != 1) printf(", ");
printf("%d", ans[pos][i] * 5);
}
puts("");
printf("Number of fish expected: %d\n\n", maxn);
}
return 0;
}

  

POJ 1042 Gone Fishing的更多相关文章

  1. POJ #1042 Gone Fishing - WA by a DP solution. TODO

    I used DP instead of Greedy. But got WA on PoJ, though it passed all web-searched cases. Maybe I hav ...

  2. POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)

    Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 30281   Accepted: 9124 Des ...

  3. poj -- 1042 Gone Fishing(枚举+贪心)

    题意: John现有h个小时的空闲时间,他打算去钓鱼.钓鱼的地方共有n个湖,所有的湖沿着一条单向路顺序排列(John每在一个湖钓完鱼后,他只能走到下一个湖继续钓),John必须从1号湖开始钓起,但是他 ...

  4. POJ 1042 Gone Fishing#贪心

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cstring> using namespace std ...

  5. POJ 1042 Gone Fishing( DP )

    题意:小明打算做一个h((1 <= h <= 16))个小时钓鱼旅行.发现这里有n(2 <= n <= 25)个湖,而且所有的湖都在一条路的旁边.小明打算从第1个湖开始钓起,每 ...

  6. Poj/OpenJudge 1042 Gone Fishing

    1.链接地址: http://bailian.openjudge.cn/practice/1042/ http://poj.org/problem?id=1042 2.题目: Gone Fishing ...

  7. Gone Fishing POJ 1042

    #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> us ...

  8. poj_1042 贪心算法

    poj 1042 gone fishing 题目要求: 由有n个湖, 按照顺序排列,一个人从第一个湖向最后一个湖行进(方向只能从湖0到湖n-1),途中可以在湖中钓鱼.在每个湖中钓鱼时,开始的5分钟内可 ...

  9. HLJU 1046: 钓鱼(数据增强版) (贪心+优化)

    1046: 钓鱼(数据增强版) Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 11  Solved: 3 [id=1046">Subm ...

随机推荐

  1. Proxmox虚拟机增加硬盘容量

    1.首先在虚拟机控制台选择调整硬盘容量,弹出窗口为增加的容量 2.重启虚拟机,用fdisk –l查看新增容量是否被识别 3.用cfdisk创建分区,分区格式为Primary 8e (Linux LVM ...

  2. Class

    1. No const constructor Unlike other member functions, constructors may not be declared as const . W ...

  3. hdu 1713 相遇周期

    求分数的最小公倍数.对于a/b c/d 先化简为最简分数,分数最小公倍数=分子的最小公倍数/分母的最大公约数. ;}

  4. jmeter 使用聚合报告分析jtl文件

    对于jmeter测试生成产生的jtl文件除了使用jemter插件来产生csv或者结果,还可以直接用聚合报告来打开,下面来介绍一下怎么操作. 1. 产生jtl文件 注意,默认情况下聚合报告插件只能分析聚 ...

  5. Eclipse 修改项目名称

    1:修改项目目录下:.project文件 <?xml version="1.0" encoding="UTF-8"?>               ...

  6. [z]Google SPDY介绍

    转自 http://blog.csdn.net/marcky/article/details/7728662 本文主要是参考Google SPDY项目主页的一些文档总结而来,目的整体上介绍SPDY协议 ...

  7. 前台将勾选的多个属性放到一个value里面,是一个字符串,传到后台

    jq function changeStreet(a){ var valk=$(a).html(); $(a).parents(".select_box").children(&q ...

  8. LR_问题_无法使用LR的Controller,提示缺少license

    问题描述 无法使用LR的Controller,提示缺少license 问题解决 使用开始->所有程序->HP LoadRunner->loadrunner,在打开界面的左上角选择co ...

  9. Spring使用外部的配置文件

    在使用Spring做web项目的时候,通常会使用到数据库的连接信息 jdbcUrl driverClass username password 那么应该如何使用这些属性呢? 如在Spring中使用数据 ...

  10. JBPM4 常用表结构

    JBPM4 常用表结构 第一部分:表结构说明 Jbpm4 共有18张表,如下,其中红色的表为经常使用的表   一:资源库与运行时表结构 1.  JBPM4_DEPLOYMENT 流程定义表 2.  J ...