Gone Fishing

Gone Fishing

John is going on a fising trip. He has h hours available (1 ≤ h ≤ 16), and there are n lakes in the area (2 ≤ n ≤ 25) all reachable along a single, one-way road. John starts at lake 1, but he can finish at any lake he wants. He can only travel from one lake to the next one, but he does not have to stop at any lake unless he wishes to. For each i = 1, . . . , n − 1, the number of 5-minute intervals it takes to travel from lake i to lake i + 1 is denoted ti (0 < ti ≤ 192). For example, t3 = 4 means that it takes 20 minutes to travel from lake 3 to lake 4.

  To help plan his fishing trip, John has gathered some information about the lakes. For each lake i, the number of fish expected to be caught in the initial 5 minutes, denoted fi (fi ≥ 0), is known. Each 5 minutes of fishing decreases the number of fish expected to be caught in the next 5-minute interval by a constant rate of di (di ≥ 0). If the number of fish expected to be caught in an interval is less than or equal to di , there will be no more fish left in the lake in the next interval. To simplify the planning, John assumes that no one else will be fishing at the lakes to affect the number of fish he expects to catch.

  Write a program to help John plan his fishing trip to maximize the number of fish expected to be caught. The number of minutes spent at each lake must be a multiple of 5.

Input

  You will be given a number of cases in the input. Each case starts with a line containing n. This is followed by a line containing h. Next, there is a line of n integers specifying fi (1 ≤ i ≤ n), then a line of n integers di (1 ≤ i ≤ n), and finally, a line of n − 1 integers ti (1 ≤ i ≤ n − 1). Input is terminated by a case in which n = 0.

Output

  For each test case, print the number of minutes spent at each lake, separated by commas, for the plan achieving the maximum number of fish expected to be caught (you should print the entire plan on one line even if it exceeds 80 characters). This is followed by a line containing the number of fish expected. If multiple plans exist, choose the one that spends as long as possible at lake 1, even if no fish are expected to be caught in some intervals. If there is still a tie, choose the one that spends as long as possible at lake 2, and so on. Insert a blank line between cases.

Sample Input

2

1

10 1

2 5

2

4

4

10 15 20 17

0 3 4 3

1 2 3

4

4

10 15 50 30

0 3 4 3

1 2 3

0

Sample Output

45, 5

Number of fish expected: 31

240, 0, 0, 0

Number of fish expected: 480

115, 10, 50, 35

Number of fish expected: 724

//钓鱼,有n个池塘,每个池塘钓鱼有个可以钓到的期望值,钓5分钟会减少期望值,可以且只能去下一个相邻池塘,并且不能回来,去下一个池塘会耗费一定的时间

问,如何决策可以钓最多鱼。并且要输出在每一个池塘钓的鱼的数量,格式也挺麻烦的

//一道贪心的题目,但是一直误差错误。。。我觉得应该没错了

就是先算出如果最后在每一个池塘结束钓鱼的话,可以钓到的最大的鱼的数量。用一个数组保存,然后,再遍历找到最大值输出就行了,

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 using namespace std;
 5 int f_i[30];//初始期望值
 6 int temp_i[30];//等于上面的
 7 int d_i[30];//期望递减值
 8 int t_i[30];//跨池塘耗费时间
 9 int n,h;
10
11 int spend[30][30];//在每一个池塘待的时间,spend[][0]是存在这个池塘钓鱼的期望值
12 int Diao(int k)
13 {
14     memset(spend[k],0,sizeof(spend[k]));
15     int i,res=0,time=h*60;
16     for (i=1;i<=k;i++)
17         temp_i[i]=f_i[i];
18     for (i=1;i<k;i++)//路上的耗费都去掉
19         time-=t_i[i]*5;
20     while (time>0)
21     {
22         int max_=-999999,max_p;
23         for (i=1;i<=k;i++)//每次找到最大的
24         {
25             if (temp_i[i]>max_)
26             {
27                 max_=temp_i[i];
28                 max_p=i;
29             }
30         }
31         if (max_>0)//还可以钓鱼
32         {
33             res+=max_;
34             temp_i[max_p]-=d_i[max_p];
35             spend[k][max_p]+=5;
36             time-=5;
37         }
38         else
39         {
40             spend[k][1]+=time;
41             break;
42         }
43     }
44     spend[k][0]=res;//0位置放期望值
45     return 0;
46 }
47
48 int main()
49 {
50     while (scanf("%d",&n)&&n)
51     {
52         scanf("%d",&h);
53         int i;
54         for (i=1;i<=n;i++)
55             scanf("%d",&f_i[i]);
56         for (i=1;i<=n;i++)
57             scanf("%d",&d_i[i]);
58         for (i=1;i<n;i++)
59             scanf("%d",&t_i[i]);
60         for (i=1;i<=n;i++)//在每一个池塘结束可钓最大值
61             Diao(i);
62         int ans=0,pos;
63         for (i=1;i<=n;i++)
64         {
65             if (spend[i][0]>ans)
66             {
67                 ans=spend[i][0];
68                 pos=i;
69             }
70             else if (spend[i][0]==ans)//等于,就要比谁在前面的池塘待的久
71             {
72                 for (int j=1;j<=n;j++)
73                 {
74                     if (spend[i][j]>spend[pos][j])
75                     {
76                         pos=i;
77                         break;
78                     }
79                     else if (spend[i][j]<spend[pos][j])
80                         break;
81                 }
82             }
83         }
84         for (i=1;i<n;i++)
85             printf("%d, ",spend[pos][i]);
86         printf("%d\n",spend[pos][i]);
87         printf("Number of fish expected: %d\n\n",ans);
88
89     }
90     return 0;
91 }

时间: 2024-08-10 02:44:49

Gone Fishing的相关文章

[ZOJ 1015]Fishing Net(MCS弦图的判定)

Description In a highly modernized fishing village, inhabitants there make a living on fishery. Their major tools, fishing nets, are produced and fixed by computer. After catching fishes each time, together with plenty of fishes, they will bring back

uva 757 Gone Fishing (贪心)

uva 757 Gone Fishing John is going on a fishing trip. He has h hours available ( ), and there are n lakes in the area ( ) all reachable along a single, one-way road. John starts at lake 1, but he can finish at any lake he wants. He can only travel fr

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

Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 30281   Accepted: 9124 Description John is going on a fishing trip. He has h hours available (1 <= h <= 16), and there are n lakes in the area (2 <= n <= 25) all reachab

贪心算法 -- gone fishing

poj 1042 gone fishing 题目要求: 由有n个湖, 按照顺序排列,一个人从第一个湖向最后一个湖行进(方向只能从湖0到湖n-1),途中可以在湖中钓鱼.在每个湖中钓鱼时,开始的5分钟内可以钓到 f[i] 条,之后每5分钟钓到的鱼数目递减 d[i] ,且每两个相邻的湖的距离 t[i] 给出(t[i] 表示 由第 i 个湖向第 i + 1个湖行进在路上花费5分钟的倍数的时间, 即如果t[3] = 4,则表示从第三个湖向第四个湖行进需要花费20分钟). 现给定总时间h 小时,求出在每个湖

ZOJ 1015 Fishing Net(判断弦图)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=15 题意:给定一个图.判断是不是弦图? 思路:(1)神马是弦图?对于一个无向图,若该图的任意一个长度大于3的环中存在一条边连接这个环上不相邻的两点,则此图称作弦图. (2)什么是团?团是原图的一个子图,子图就是包含了原图的某些点,那么就要包含这些点之间的边.并且团不是一般的子图而是一个完全子图,就是这个子图的任意两个顶点之间都有边.下面的ABCD就是原图的一个团. (

ZOJ 1015 Fishing Net(弦图判定)

In a highly modernized fishing village, inhabitants there make a living on fishery. Their major tools, fishing nets, are produced and fixed by computer. After catching fishes each time, together with plenty of fishes, they will bring back the shabby

uva757 - Gone Fishing(贪心)

题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊只有一条通路将这些湖泊相连.每个湖泊都会给最开始5分钟间隔内可以调到的鱼(f),然后给每过5分钟减少的鱼的数量(d),如果当前的鱼少于等于减少的数量,说明在下个5分钟没有鱼.还有过每条道路的所要耗费的时间(N-1),时间都是以5分钟为单位的.渔者可以在任意一个湖泊钓鱼,但是起始位置是在湖泊1.问H小时后,渔者怎样合理的在每个湖泊分配时间,可以得到的鱼最多.如果得到最多的鱼的方式有多种,则取在前面的湖泊耗时最久的那一种.

bzoj 1242: Zju1015 Fishing Net 弦图判定

1242: Zju1015 Fishing Net弦图判定 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 214  Solved: 81[Submit][Status][Discuss] Description 在 一个高度信息化的渔村,鱼网的制作和修补都是由电脑完成.众所周知,鱼网是由网组成的(废话),网组成的东西叫网眼.如果网眼够小,就能捕到很多鱼:如果 网眼太大,鱼就会全部漏走.每次捕鱼回来,鱼网都会烂得很厉害,小网眼会变成网眼,那鱼网就需

POJ-1042 Gone Fishing (贪心法求最佳钓鱼方案

Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 28075   Accepted: 8371 Description John is going on a fishing trip. He has h hours available (1 <= h <= 16), and there are n lakes in the area (2 <= n <= 25) all reachab