PAT1046-Shortest Distance
C语言源码:[cpp]#include<stdio.h>#define maxsize 100010int T[maxsize];int main(){int n,i,m,sum,j,min,temp;scanf("%d",&n);sum=0;for(i=1;i<=n;i++){scanf("%d",&temp);T[i]=sum;sum+=temp;}scanf("%d",&m);while(m--){ www.zzzyk.comscanf("%d %d",&i,&j);min=0;if(i>j){temp=i;i=j;j=temp;}min=T[j]-T[i];if(2*min>sum)min=sum-min;printf("%d\n",min);}return 0;}
补充:软件开发 , C++ ,