#include<stdio.h>
int main()
{
int n,m,a,b,tem,pre,p;
int i,j;
int ans[];
while(scanf("%d",&n)!=EOF)
{
ans[]=;
for(i=;i<=n;i++)
{
scanf("%d",&tem);
ans[i]=ans[i-]+tem;
}
getchar();
scanf("%d",&m);
for(i=;i<m;i++)
{
getchar();
scanf("%d %d",&a,&b);
if(a<b)
{
pre=a;
p=b;
}
else
{
p=a;
pre=b;
} int sum1=ans[p-]-ans[pre-];
int sum2=ans[pre-]+ans[n]-ans[p-]; printf("%d\n",sum1<sum2?sum1:sum2);
}
} return ;
}

1046 Shortest Distance (20)的更多相关文章

  1. PAT甲 1046. Shortest Distance (20) 2016-09-09 23:17 22人阅读 评论(0) 收藏

    1046. Shortest Distance (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...

  2. 1046 Shortest Distance (20 分)

    1046 Shortest Distance (20 分) The task is really simple: given N exits on a highway which forms a si ...

  3. PAT 甲级 1046 Shortest Distance (20 分)(前缀和,想了一会儿)

    1046 Shortest Distance (20 分)   The task is really simple: given N exits on a highway which forms a ...

  4. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  5. PAT Advanced 1046 Shortest Distance (20 分) (知识点:贪心算法)

    The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...

  6. 1046 Shortest Distance (20分)

    The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...

  7. PAT (Advanced Level) 1046. Shortest Distance (20)

    处理一下前缀和. #include<iostream> #include<cstring> #include<cmath> #include<algorith ...

  8. PAT甲题题解-1046. Shortest Distance (20)-做了一个假的最短路,水

    一开始以为是最短路,结果是给你一个环,让你求环上两点之间的距离...那还做毛线 然而还是得做毛线 #include <iostream> #include <cstdio> # ...

  9. 【PAT甲级】1046 Shortest Distance (20 分)

    题意: 输入一个正整数N(<=1e5),代表出口的数量,接下来输入N个正整数表示当前出口到下一个出口的距离.接着输入一个正整数M(<=10000),代表询问的次数,每次询问输入两个出口的序 ...

随机推荐

  1. SQL Server 日期 时间类型

    --1毫秒=0.001秒 --1微秒=0.000 001秒 --1纳秒=0.000 000 001秒 --datetime精度不大好,末尾值只能是这3种: .000, .003, or .007 -- ...

  2. ionic获取事件中的对象

    ng-click="submit1($event, 'argsTest’)" $scope.submit1=function(event, args){ var target = ...

  3. C# PLINQ 内存列表查询优化历程

    产品中(基于ASP.NET MVC开发)需要经常对药品名称及名称拼音码进行下拉匹配及结果查询.为了加快查询的速度,所以我最开始就将其加入内存中(大约有六万五千条数据). 下面附实体类. public ...

  4. C#算法基础之冒泡排序

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. Fragment 整个生命周期

      时间 2014-05-21 17:09:53 CSDN博客原文 http://blog.csdn.net/linfeng24/article/details/26491407 Fragment 生 ...

  6. 【Linq to Object】使用LINQ实现左链接加GROUP BY查询

    直接上代码留记 var list = (from item in (from tb1 in fileDirList join tb2 in fileInfoList on tb1.FileDirId ...

  7. JSP之初识2

    <与%之间不可有空格,但是后面可以有空格 <%@ page language="java" import="java.util.*" pageEnc ...

  8. 第十三篇、Swift_Nav自定义返回按钮后或者隐藏导航栏,Pop返回手势失效的解决方法 Pop全局返回添加的方法

    边缘的pop返回手势: override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.purple ...

  9. (转)基于Redis Sentinel的Redis集群(主从&Sharding)高可用方案

    转载自:http://warm-breeze.iteye.com/blog/2020413 本文主要介绍一种通过Jedis&Sentinel实现Redis集群高可用方案,该方案需要使用Jedi ...

  10. reduce + Promise 顺序执行代码

    本文地址: http://www.cnblogs.com/jasonxuli/p/4398742.html 下午的太阳晒得昏昏沉沉,和上周五一样迷糊,看一段代码半天没看明白,刚才不知不觉眯了几分钟,醒 ...