您的位置:首页 > 其它

1046. Shortest Distance (20)

2015-02-05 17:12 288 查看
点击打开链接

最后一个超时

#include <cstdio>
#define MAX 100100
int dis[MAX];
int n;
int main(){
freopen("in.txt","r",stdin);
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&dis[i]);
}
int m;
scanf("%d",&m);
for(int j=0;j<m;j++){
int a,b;
scanf("%d %d",&a,&b);
a--;b--;
int sp=0,ps=0;
int i=a%n;
while(1){
if(i%n==b){
break;
}
sp+=dis[i++];
}
i=a%n;
while(1){
i=(i+n-1)%n;
ps+=dis[i];
if(i%n==b){
break;
}
}
i=ps<sp?ps:sp;
printf("%d\n",i);
}
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: