POJ1042 Gone Fishing

Source: Internet
Author: User

Dynamic planning.

To a fish pond must pass through the former fish pond, and can not be returned after passing. Assuming that the n fish ponds in 1-n are fishing, you can pre-subtract the time required from 1 to n (sooner or later anyway), then ignore the "go-to-go" limit and think that you can switch freely between the fish ponds (because it is equivalent to having enough fish in one pond to catch a predetermined number of times to the next fish pond).

Use the heap to maintain and find the most efficient fish ponds, and go there to fish, then update the heap ... Keep repeating until the time is up.

1 /*by Silvern*/2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <queue>8 using namespacestd;9 Const intmxn= *;Ten structfh{ One     intf,d; A     intID; - }A[MXN]; -  the BOOL operator< (ConstFH X,ConstFH y) { -     if(X.F!=Y.F)returnx.f<y.f; -     returnX.id>y.id; - } +priority_queue<fh>q;//default Dagen - intDIS[MXN]; + intANS[MXN],TMP[MXN]; A intN; at voidinit () { -memset (ans,0,sizeofans); -Memset (A,0,sizeofa); -dis[1]=0; - } - intMain () { in      while(SCANF ("%d", &n) &&N) { - init (); to         intTime ; +scanf"%d",&Time ); -time*= A;//The read-in time is measured in hours, and the actual calculation is 5 minutes as a unit the         inti,j; *          for(i=1; i<=n;i++) a[i].id=i; $          for(i=1; i<=n;i++) scanf ("%d",&a[i].f);Panax Notoginseng          for(i=1; i<=n;i++) scanf ("%d",&a[i].d); -          for(i=2; i<=n;i++){ thescanf"%d",&j); +dis[i]=j+dis[i-1]; A         } theans[0]=-1; +          for(i=1; i<=n;i++){ -             intmx=0; $memset (TMP,0,sizeoftmp); $             intBas=time-dis[i];//time available for fishing -              while(!q.empty ()) Q.pop (); -              for(j=1; j<=i;j++) Q.push (A[j]); the FH x; -              while(bas>0){//FishingWuyix=q.top (); the Q.pop (); -bas--; Wumx+=x.f; -tmp[x.id]++; Aboutx.f-=x.d; $                 if(x.f<0) x.f=0; - Q.push (x); -             } -             if(mx>ans[0]){//Update Answer Aans[0]=MX; +                  for(j=1; j<=i;j++) ans[j]=Tmp[j]; the             } -         } $          for(i=1; i<n;i++) printf ("%d,", ans[i]*5); theprintf"%d\n", ans[n]*5); theprintf"Number of fish expected:%d\n\n", ans[0]);  the     } the     return 0; -}

POJ1042 Gone Fishing

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.