Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这题真是烦躁,老是WA湘大OJ就能过,北大OJ就不能过了 #include<iostream> #include<cstdio> #include<cstring> #define N 30 using namespace std; int greedy[N],h; typedef struct Lake{ int fish,dec,time,curr,ans,tsp[N]; }Lake; Lake la[N]; int select(int end,int &temp){ int i,from; for(i=0;i<=end;i++) if(temp<la[i].curr){ temp=la[i].curr; from=i; } if(temp==0) return -1; la[from].curr=la[from].curr-la[from].dec; if(la[from].curr<0) la[from].curr=0; return from; } void fishing(int end){ int i,tim=h*60,li,get; for(i=0;i<=end;i++){ la[i].curr=la[i].fish; tim=tim-la[i].time*5; } greedy[end]=0; while(0<tim){ get=0; li=select(end,get); if(li==-1) break; la[li].tsp[end]+=5; tim-=5; greedy[end]+=get; } if(li==-1) la[0].tsp[end]+=tim; } int main(){ int n,i,answer,wlake; scanf("%d",&n); while(n!=0){ scanf("%d",&h); for(i=0;i<n;i++){ scanf("%d",&la[i].fish); memset(la[i].tsp,0,sizeof(la[i].tsp)); greedy[i]=0; } for(i=0;i<n;i++) scanf("%d",&la[i].dec); la[0].time=0; for(i=1;i<n;i++) scanf("%d",&la[i].time); for(i=n-1;0<=i;i--) fishing(i); answer=-1; wlake=0; for(i=n-1;0<=i;i--) if(answer<greedy[i]){ answer=greedy[i]; wlake=i; } if(answer==0) wlake=0; for(i=0;i<n-1;i++) printf("%d, ",la[i].tsp[wlake]); printf("%d\n",la[i].tsp[wlake]); printf("Number of fish expected: %d\n\n",answer); scanf("%d",&n); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator