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 ...
随机推荐
- WCF 笔记 (2) - 传输泛型 List 对象
WCF 笔记 (2) - 传输泛型 List 对象 本帖介绍怎么在 WCF 中,在 Server-side 和 Client-side 之间,传递默认无法传输的 List<T>.List& ...
- ZOJ 2724 Windows Message Queue (优先级队列,水题,自己动手写了个最小堆)
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...
- SNAT
http://blog.chinaunix.net/uid-2628744-id-2454879.html
- GOOGLE搜索秘籍完全公开
一,GOOGLE简介 Google(www.google.com)是一个搜索引擎,由两个斯坦福大学博士生Larry Page与Sergey Brin于1998年9月发明,Google Inc. 于19 ...
- POJ1013Counterfeit Dollar
这个题主要是判断硬币真假,可能轻可能重,称三次,要输出哪枚是假币,还要输出是重的还是轻的,所以最主要的是标记变量 #include<cstdio> #include<cstring& ...
- Project Euler 99:Largest exponential 最大的幂
Largest exponential Comparing two numbers written in index form like 211 and 37 is not difficult, as ...
- Filter(过滤器)常见应用
孤傲苍狼 只为成功找方法,不为失败找借口! javaweb学习总结(四十六)——Filter(过滤器)常见应用 一.统一全站字符编码 通过配置参数charset指明使用何种字符编码,以处理Html F ...
- IOS中实现图片点击全屏预览
//// ViewController.m// XWZoomImageView//// Created by xiao on 15/11/13.// Copyright © 2015年 xiao. A ...
- iOS 开发--开源图片处理圆角
概述 开源项目名称:HYBImageCliped 当前版本:2.0.0 项目用途:可给任意继承UIView的控件添加任意多个圆角.可根据颜色生成图片且可带任意个圆角.给UIButton设置不同状态下的 ...
- JavaWeb项目开发案例精粹-第3章在线考试系统-004Service层
1. package com.sanqing.service; import java.util.List; import com.sanqing.po.Student; public interfa ...