题意:一个人要在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. hdu1151 Air Raid

    http://acm.hdu.edu.cn/showproblem.php?pid=1151 增广路的变种2:DAG图的最小路径覆盖=定点数-最大匹配数 #include<iostream> ...

  2. [z]CAP原理和BASE思想

    分布式领域CAP理论,Consistency(一致性), 数据一致更新,所有数据变动都是同步的Availability(可用性), 好的响应性能Partition tolerance(分区容错性) 可 ...

  3. MIT算法导论——第二讲.Solving Recurrence

    本栏目(Algorithms)下MIT算法导论专题是个人对网易公开课MIT算法导论的学习心得与笔记.所有内容均来自MIT公开课Introduction to Algorithms中Charles E. ...

  4. 浅析Quartz的集群配置

    浅析Quartz的集群配置(一) 收藏人:Rozdy     2015-01-13 | 阅:1  转:22    |   来源   |  分享               1 基本信息 摘要:Quar ...

  5. EF 实体关系

    基于共享主键的一对一: this.HasRequired(t => t.TRDConInfo) .WithOptional(t => t.TRDFoundationProjCheck); ...

  6. python学习中,list/tuple/dict格式化遇到的问题

    昨天上了python培训的第一课,学习了基础知识.包括类型和赋值,函数type(),dir(),id(),help()的使用,list/tuple/dict的定义以及内置函数的操作,函数的定义,控制语 ...

  7. [POJ1753]Flip Game(开关问题,枚举)

    题目链接:http://poj.org/problem?id=1753 和上一个题一样,将初始状态存成01矩阵,就可以用位运算优化了.黑色白色各来一遍 /* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏ ...

  8. IDEA 创建Web项目并在Tomcat中部署运行

    IDEA 14.0.5 apache-tomcat-8.0.32 步骤:File->New Project,在Java列表中勾选Web Application(3.1),点击Next 建立web ...

  9. uva 10453 - Make Palindrome(dp, 记录路径)

    题目 题意: 给一个字符串 ,判断最少插入多少个字符 使字符串成为回文串, 并输出回文串. 思路:先用dp判断需要个数, 再递归输出路径. #include <iostream> #inc ...

  10. Android远程图片获取和本地缓存

    对于客户端——服务器端应用,从远程获取图片算是经常要用的一个功能,而图片资源往往会消耗比较大的流量,对 应用来说,如果处理不好这个问题,那会让用户很崩溃,不知不觉手机流量就用完了,等用户发现是你的应用 ...