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 |
实在是搞不懂这两个程序有什么区别了程序1: #include <stdio.h> #define M 30 int i, j, n, h, ri; int f[M], tf[M], d[M], t[M], temp, sum, maxsum, max, rec[M], tp[M]; int main() { while(scanf("%d",&n),n>0) { scanf("%d", &h); h *= 12; for(i = 0; i < n; i ++) scanf("%d",&tf[i]); for(i = 0; i < n; i ++) scanf("%d",&d[i]); t[0] = 0; for(i = 1; i < n ; i ++) { scanf("%d",&t[i]); t[i] += t[i-1]; } maxsum = 0; for(i = n-1; i >= 0; i --) { temp = h - t[i]; for(j = 0; j <= n-1; j ++ ) { f[j] = tf[j]; tp[j] = 0; } sum = 0; while( temp > 0 ) { ri = 0; for( j=1; j<=i; j++ ) if( f[j]>f[ri] ) ri=j; if(f[ri]==0)break; sum+=f[ri]; f[ri]-=d[ri]; if(f[ri] < 0 )f[ri] = 0; tp[ri] += 5; temp--; } tp[0]+=temp*5; if(sum > maxsum) { for( j=0; j<n; j++ ) rec[j] = tp[j]; maxsum = sum; } else if(sum == maxsum) { for( j = 0; j < n; j ++ ) if(rec[j] <= tp[j])break; if( j != n ) for( j = 0; j < n; j ++ ) rec[j] == tp[j]; } } printf("%d", rec[0]); for(j = 1; j < n; j ++) printf(", %d", rec[j]); printf( "\nNumber of fish expected: %d\n\n", maxsum ); } return 0; } 程序2: #include <stdio.h> int f[26],d[26],t[26],ff[26],tt[26]; int best_t[26],max_fish,n,h; int main() { int i,j,k,left_time,fish; while(scanf("%d", &n),n>0) { scanf("%d", &h);h*=12; for(i=0;i<n;i++) scanf("%d", &f[i]); for(i=0;i<n;i++) scanf("%d", &d[i]); t[0] = 0; for(i=1;i<n;i++) { scanf("%d", &t[i]); t[i] += t[i-1]; } max_fish = 0; for(k=n-1;k>=0;k--) { left_time = h-t[k]; for(i=0;i<n;i++) { ff[i] = f[i]; tt[i] = 0; } fish = 0; while(left_time > 0) { j = 0; 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 --; } tt[0] += left_time*5; if(fish > max_fish) { for(i=0;i<n;i++) best_t[i] = tt[i]; max_fish = fish; } else if( fish==max_fish ) { for(i=0;i<n;i++) if(best_t[i] <= tt[i]) break; if(i != n) for(i=0;i<n;i++)best_t[i] = tt[i]; } } printf("%d", best_t[0]); for(j = 1; j < n; j ++) printf(", %d", best_t[j]); printf( "\nNumber of fish expected: %d\n\n", max_fish ); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator