zoukankan      html  css  js  c++  java
  • POJ 1042 Gone Fishing

    Gone Fishing
     
    Time Limit: 2000MS   Memory Limit: 32768K
    Total Submissions: 25233   Accepted: 7423

    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 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 
    

    Source

     
     
     
    题意:(转)john现有h个小时的空闲时间,他打算去钓鱼。john钓鱼的地方共有n个湖,所有的湖沿着一条单向路顺序排列(john每在一个湖钓完鱼后,他只能走到下一个湖继续钓),john必须从1号湖开始钓起,但是他可以在任何一个湖结束他此次钓鱼的行程。john在每个湖中每5分钟钓的鱼数(此题中以5分钟作为单位时间),随时间的增长而线性递减。而每个湖中头5分钟可以钓到的鱼数以及每个湖中相邻5分钟钓鱼数的减少量,input中均会给出。并且John从任意一个湖走到它下一个湖的时间input中也都给出。
     
    #include<stdio.h>
    #include<string.h>
    
    int n,h;
    int f[30],d[30],t[30];
    int count[30],tmp[30],cal[30],record[30][30];
    
    void greedy(){
        int i,j;
        for(i=1;i<=n;i++){
            int sum_time=0;
            memset(count,0,sizeof(count));
            for(j=1;j<=n;j++)
                tmp[j]=f[j];
            int tmp_h=h*12;
            for(j=1;j<=i-1;j++)
                sum_time+=t[j];
            tmp_h-=sum_time;
            int sum=0,max,flag;
            int k;
            while(tmp_h>0){
                max=0,flag=0;
                for(j=1;j<=i;j++)
                    if(max<tmp[j]){
                        max=tmp[j];
                        k=j;
                        flag=1;
                    }
                if(!flag)
                    break;
                sum+=tmp[k];
                tmp[k]-=d[k];
                count[k]++;
                tmp_h--;
            }
            count[1]+=tmp_h;
            for(j=1;j<=n;j++)
                count[j]*=5;
            for(j=1;j<=n;j++)
                record[i][j]=count[j];
            cal[i]=sum;
        }
    }
    
    int main(){
        int i,j;
        while(scanf("%d",&n) && n){
            scanf("%d",&h);
            for(i=1;i<=n;i++)
                scanf("%d",&f[i]);
            for(i=1;i<=n;i++)
                scanf("%d",&d[i]);
            for(i=1;i<n;i++)
                scanf("%d",&t[i]);
    
            greedy();
    
            int k;
            j=1;
            for(i=1;i<=n;i++){
                if(cal[i]>cal[j])
                    j=i;
                else if(cal[i]==cal[j]){
                    for(k=1;k<=n;){
                        if(record[i][k]>record[j][k]){
                            j=i;
                            break;
                        }else if(record[i][k]==record[j][k])
                            k++;
                        else
                            break;
                    }
                }
            }
            printf("%d,",record[j][1]);
            for(k=2;k<n;k++)
                printf(" %d,",record[j][k]);
            printf(" %d\n",record[j][k]);
            printf("Number of fish expected: %d\n\n",cal[j]);
        }
        return 0;
    }
  • 相关阅读:
    Kafka 不停机修改某一个topic数据保存时间
    jvisualvm 工具使用
    jmap命令详解----查看JVM内存使用详情
    C语言计算时间函数 & 理解linux time命令的输出中“real”“user”“sys”的真正含义
    JVM NativeMemoryTracking 分析堆外内存泄露
    java调用shell脚本并传递参数
    top -H -p查看某个进程内部线程占用情况分析: pstack显示每个进程的栈跟踪
    shell-awk 按列求和
    HTML&CSS基础-ps的基本操作
    HTML&CSS基础-清除浮动
  • 原文地址:https://www.cnblogs.com/jackge/p/2847870.html
Copyright © 2011-2022 走看看