题意:一个人要在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. poj 1797 Heavy Transportation(最短路变种2,连通图的最小边)

    题目 改动见下,请自行画图理解 具体细节也请看下面的代码: 这个花了300多ms #define _CRT_SECURE_NO_WARNINGS #include<string.h> #i ...

  2. POJ 1785 Binary Search Heap Construction(裸笛卡尔树的构造)

    笛卡尔树: 每个节点有2个关键字key.value.从key的角度看,这是一颗二叉搜索树,每个节点的左子树的key都比它小,右子树都比它大:从value的角度看,这是一个堆. 题意:以字符串为关键字k ...

  3. javascript背景淡入淡出

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  4. POJ2503Babelfish

    http://poj.org/problem?id=2503 这个题一开始是想用字典树,发现太麻烦..... #include<cstdio> #include<cstring> ...

  5. POJ2996Help Me with the Game

    http://poj.org/problem?id=2996 又是一个大模拟题,表示做模拟题做的恶心,这个题主要是对数据的处理,从表格中将数据取出来再进行处理即可. 主要注意的点就是:1.KQRBN五 ...

  6. 简单的线程同步问题:两个线程交替执行N次【Synchronized、Lock、ArrayBlockingQueue】

    方法一:传统的线程方法import org.apache.log4j.Logger; /** * 两个线程执行的代码片段要实现同步互斥的效果,它们必须用同一个Lock对象.<br/> * ...

  7. lintcode 中等题 :Maximum Product Subarray 最大连续乘积子序列

    题目 乘积最大子序列 找出一个序列中乘积最大的连续子序列(至少包含一个数). 样例 比如, 序列 [2,3,-2,4] 中乘积最大的子序列为 [2,3] ,其乘积为6. 解题  法一:直接暴力求解 时 ...

  8. lintcode 中等题:N Queens N皇后问题

    题目: N皇后问题 n皇后问题是将n个皇后放置在n*n的棋盘上,皇后彼此之间不能相互攻击.<不同行,不同列,不同对角线> 给定一个整数n,返回所有不同的n皇后问题的解决方案. 每个解决方案 ...

  9. 初识io流条件状态

    一  流状态    C++中的输入输出系统负责记录每一个输入输出操作的结果信息,这些当前的状态信息被包含在io_state类型的对象中.io_state是一个枚举类型(就像open_mode一样),以 ...

  10. [mock]8月8日

    第一题是整数的方阵,求其中的子方阵,和最大.返回最大和以及子方阵宽度.因为做了topcoder的题,所以比较顺手,O(n^3)的复杂度. pair<int,int> maxiSum(vec ...