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 |
那个程序有一个不太明显的错误In Reply To:这个和正向,反向关系不大吧 Posted by:semonteer at 2006-03-22 22:55:31 //下面这个程序是可以AC的(我改过了) //循环从n到1所以tt[]的总和总是大于best[],因此在fish = max_fish时, //第一个不相同的值tt[i] 必然大于 best[i], 也就是,无论是<, 还是<=都应 //该会break, 完全不需要那个循环.结果由于一个小错误,加上后反而出了问题 //数据是极少错的,在怀疑数据有错之前,还是先怀疑怀疑自己的程序吧 #include <stdio.h> #include<iostream.h> int n,h; int f[26],d[26],t[26]; int ff[26],tt[26]; int best_t[26],max_fish; int main() { int i,j,k,left_time,fish; cin>>n; while(n>0) { cin>>h; for(i=1;i<=n;i++) { cin>>f[i]; } for(i=1;i<=n;i++) { cin>>d[i]; } t[1] = 0; for(i=2;i<=n;i++) { cin>>t[i]; t[i] += t[i-1]; } max_fish = 0; for(k=n;k>=1;k--) { fish = 0; left_time = h*60-t[k]*5;////// for(i=1;i<=n;i++) { ff[i] = f[i]; tt[i] = 0; } while(left_time > 0) { j = 1; for(i=1;i<=k;i++) { if(ff[i] > ff[j]) j = i; } if(ff[j] == 0)////鱼都没了; break; tt[j] += 5; fish += ff[j]; ff[j] -= d[j]; if(ff[j] <=0) ff[j] = 0; left_time -= 5; } //left_time>=0; tt[1] += left_time; if(fish > max_fish)/// = ?????如何抉择呢?? { for(i=1;i<=n;i++) best_t[i] = tt[i]; max_fish = fish; } else if( fish==max_fish ) { for(i=1;i<=n;i++) if(best_t[i] <tt[i])//奇怪之处:改成best_t[i] <tt[i]就过不了!!!! break; if(i != n+1) { for(i=1;i<=n;i++)best_t[i] = tt[i]; max_fish = fish; } } }////////////////////////////////// for(i=1;i<n;i++) { cout<<best_t[i]<<", "; best_t[i] = 0; } cout<<best_t[n]<<endl; best_t[n] = 0; cout<<"Number of fish expected: "<<max_fish<<endl; cout<<endl; cin>>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