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 |
哪位帮我看看,是哪里出了问题./* **1701pkuacm. */ #include <stdio.h> #include <stdlib.h> main() { long min=99999999,s,num; int final,i,time,a,b,m; int *k; long *up,*down; scanf("%d",&time); while(time--) { scanf("%d%d%d",&m,&a,&b); k=(int*)malloc(sizeof(int)*(m+1)); up=(long*)malloc(sizeof(long)*(m+1)); down=(long*)malloc(sizeof(long)*(m+1)); for(i=1;i<=m;i++) scanf("%d",&k[i]); s=num=up[m]=0; for(i=m-1;i>=1;i--) { s=s+num+a*k[i+1]; up[i]=up[i+1]+s; num=num+k[i+1]; } s=num=down[1]=0; for(i=2;i<=m;i++) { s=s+num+b*k[i-1]; down[i]=down[i-1]+s; num=num+k[i-1]; } for(i=1;i<=m;i++) { if(up[i]+down[i]<min) { min=up[i]+down[i]; final=i; } } printf("%d\n",final); free(k); free(up); free(down); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator