POJ 1042 Gone Fishing
题意:一个人要在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的更多相关文章
- 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 ...
- POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)
Gone Fishing Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 30281 Accepted: 9124 Des ...
- poj -- 1042 Gone Fishing(枚举+贪心)
题意: John现有h个小时的空闲时间,他打算去钓鱼.钓鱼的地方共有n个湖,所有的湖沿着一条单向路顺序排列(John每在一个湖钓完鱼后,他只能走到下一个湖继续钓),John必须从1号湖开始钓起,但是他 ...
- POJ 1042 Gone Fishing#贪心
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cstring> using namespace std ...
- POJ 1042 Gone Fishing( DP )
题意:小明打算做一个h((1 <= h <= 16))个小时钓鱼旅行.发现这里有n(2 <= n <= 25)个湖,而且所有的湖都在一条路的旁边.小明打算从第1个湖开始钓起,每 ...
- Poj/OpenJudge 1042 Gone Fishing
1.链接地址: http://bailian.openjudge.cn/practice/1042/ http://poj.org/problem?id=1042 2.题目: Gone Fishing ...
- Gone Fishing POJ 1042
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> us ...
- poj_1042 贪心算法
poj 1042 gone fishing 题目要求: 由有n个湖, 按照顺序排列,一个人从第一个湖向最后一个湖行进(方向只能从湖0到湖n-1),途中可以在湖中钓鱼.在每个湖中钓鱼时,开始的5分钟内可 ...
- HLJU 1046: 钓鱼(数据增强版) (贪心+优化)
1046: 钓鱼(数据增强版) Time Limit: 1 Sec Memory Limit: 128 MB Submit: 11 Solved: 3 [id=1046">Subm ...
随机推荐
- HDU4612 Warm up 边双连通分量&&桥&&树直径
题目的意思很简单,给你一个已经连通的无向图,我们知道,图上不同的边连通分量之间有一定数量的桥,题目要求的就是要你再在这个图上加一条边,使得图的桥数目减到最少. 首先要做的就是找出桥,以及每个点所各自代 ...
- POJ 1915
#include<iostream> #include<stdio.h> #define MAXN 350 #include"queue" using na ...
- Java快速排序 分别以数组0位作为基准 和最后一位作为基准的排序演示
package util; public class Pub { public static void beforeSort(int[] arr){ System.out.println(" ...
- Mac 如果一定要写个锁屏程序的话就这样
package test; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import ...
- Oracle中关于数据库实例名与数据库服务名(转载)
今天同事,出现了数据库连接失败的问题,一起百度了一下,结果总算解决了,以下是一些转载过来的普及知识. 1.查询数据库名:select name,dbid from v$database;或者命令行:s ...
- SQLite操作(C# )
C#连接SQLite的...方法 http://www.cnblogs.com/virusswb/archive/2010/09/17/SQLite1.html 1 SQLite简介 SQLite,是 ...
- linux服务器下发送邮件
系统管理人员经常会遇到对于设备或者任务的预警与通知,通常情况有发送短信.邮件等方式.发送短信一般来说需要有短信猫(硬件)或者调用libfetion给飞信用户发送.本文介绍几种简单的发送邮件的方式. 本 ...
- ORA-12571 : TNS : 包写入程序失败
错误原因 解决方案 修改D:/oracle/ora92/network/admin目录下sqlnet.ora,将”NAMES.DEFAULT_DOMAIN =” 这一行用#注释掉,将“SQLNET.A ...
- 如何用Maven创建一个普通Java项目
一下内容包括:用Maven创建一个普通Java项目,并把该项目转成IDEA项目,导入到IDEA,最后把这个项目打包成一个jar文件. 有时候运行mvn命令失败,重复运行几次就OK了,无解(可能因为网络 ...
- 关于java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream解决办法
吉林的一个项目有个错误找了一天,有段报错是: java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream 1.遇到过两次,第 ...