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,大家帮我看一下,谢谢!#include<stdio.h> #define N 30001 int main() { int a[N]; int i,j,k,n,log_len; while(scanf("Sample Input %d",&i)!=EOF)//for each test cases { scanf(" %d%d",&n,&log_len); for(j=0;j<n;j++) scanf(" %d",a+j);//the height of each tree int remain[N],min,flag;//flag get the best year, int t,sum_remain; for(k=log_len-1;k>=0;k--)//waiting years { sum_remain=0; if(k==log_len-1)//the last year { for(t=0;t<n;t++)//for each tree { remain[t]=(a[t]+k)%log_len;//the remain of each tree after k years sum_remain+=remain[t];//the total remain in k year } min=sum_remain; flag=log_len-1; } else// another log_len-1 years { for(t=0;t<n;t++)//for each tree { remain[t]=(a[t]+k)%log_len;//the remain sum_remain+=remain[t];//the total remain in k year } if(min>sum_remain) { min=sum_remain; flag=k; } }//else }//for k years printf("Sample Output %d\n",i); printf("%d\n",flag); }// while for each test cases return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator