Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

PAT1046-Shortest Distance

$
0
0

题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1046

C语言源码:

#include<stdio.h>
#define maxsize 100010
int 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--)
	{
		scanf("%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;
}


作者:leizh007 发表于2013-3-12 16:11:48 原文链接
阅读:0 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles