UVa 757:gone Fishing

Source: Internet
Author: User
Tags bool current time printf

"Topic link"

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_ problem&problem=698

"Original title" John is going in 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 and but he can finish in any lake he wants. He can only travel from one lake to the next one, and but he does does not have to stop in any lake unless him wishes to. For each, the number of 5-minute intervals it takes to travel from Lake I to Lake i + 1 is denoted Ti (). For example, T3 = 4 means-it takes minutes to travel from Lake 3 to Lake 4.

To help plan he fishing trip, John has gathered some information about the lakes. For all I, the number of fish expected to being caught in the initial 5 minutes, denoted Fi (), is known. Each 5 minutes of fishing decreases the number of fish expected to is caught in the next 5-minute interval by a constant R Ate di (). If the number of fish expected to was caught in a interval is less than or equal to Di, there'll be no more fish left in The lake in the next interval. To simplify the planning, John assumes that no one else would be fishing at the lakes to affect the number of fish he expec TS to catch.

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

Input

You are given a number of cases in the input. Each case is starts with a line containing N. This is followed by a line containing H. Next, there is a line of the n integers specifying fi (), then a line of n integers di (), and finally, a line of n-1 inte Gers ti (). The Input is terminated by a case in which n = 0.

Output

For the all test case, print the number of minutes spent in each lake, separated by commas, for the plan achieving the Maximu M number of fish expected to is caught (you should print the entire plan on one line even if it exceeds). 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 in Lake 1, even if no fish are expected to be Caug HT in some intervals. If There is still a tie, choose the one this spends as long as possible at Lake 2, and. Insert a blank line between cases.

Sample Input

2
1
1
2 5 2
4 4 m
0 3 4 3 1 2 3 4 M 4 0 3 3
1 2 3
0


Sample Output

5 of
Fish expected:31,

0, 0, 0 number of
fish expected:480,
Numbe R of Fish expected:724


"Analysis and Summary"

This column more highlights: http://www.bianceng.cn/Programming/sjjg/

Super Classic A greedy question, lrj Black Book greedy chapter of the first example.

I'm using the heap to achieve it.

Code

* * Uva:757-gone Fishing * greedy * time:0.044s (UVa), 79MS (POJ) * author:d_double * * * */#include <iost ream> #include <cstring> #include <cstdio> #include <queue> #define MAXN using namespace St  
D  
int h,n;  
      
int ANS[MAXN], TMP[MAXN];        struct node{int no;      Number of lakes int rate;      Every 5 minutes the fish catches int down;      Reduced number of anglers per 5 minutes int time;  
            From the first lake to the current time of this lake friend bool operator < (const node&a,const node&b) {if (a.rate!=b.rate)  
        Return a.rate<b.rate; Return a.no>b.no;  
      
If the fish is the same every 5 minutes, the priority number is to catch the small lake}}ARR[MAXN];  
      
priority_queue<node>que;  
    void greedy () {int maxsum=-10000;  
        for (int i=0; i<n; ++i) {//enumeration of fishing 1~i lakes while (!que.empty ()) Que.pop ();  
      
        for (int j=0; j<=i; ++j) Que.push (arr[j));  
        int Lefttime=h*60-arr[i].time, sum=0;  
      
     memset (tmp, 0, sizeof (TMP));   while (Lefttime > 0) {Node temp=que.top ();  
            Que.pop ();  
            if (temp.rate<=0) break;  
            sum + + temp.rate;  
            Temp.rate-= Temp.down;  
            Tmp[temp.no] + + 5;  
            Que.push (temp);  
        Lefttime-= 5; } if (lefttime>0) tmp[0] + = Lefttime;  
            Note that the rest of the time is added to the first lake if (Sum > Maxsum) {maxsum=sum;  
        for (int j=0; j<n; ++j) ans[j]=tmp[j];  
    printf ("%d", ans[0]);  
    for (int i=1; i<n; ++i) printf (",%d", ans[i]);  
    printf ("\ n");  
printf ("Number of fish expected:%d\n", maxsum);  
    int main () {bool flag=false;  
        while (~SCANF ("%d", &n) &&n) {scanf ("%d", &h);  
            for (int i=0; i<n; ++i) {scanf ("%d", &arr[i].rate);  
        arr[i].no = i; for (int i=0; i<n; ++i) {scanf ("%D ", &arr[i].down);  
        } arr[0].time=0;  
            for (int i=1; i<=n-1; ++i) {int t;  
            scanf ("%d", &t);  
        Arr[i].time = arr[i-1].time+t*5;  
        } if (flag) printf ("\ n");  
        else flag=true;   
    Greedy ();  
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.