1046 Shortest Distance (20)
#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)的更多相关文章
- 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 ...
- 1046 Shortest Distance (20 分)
1046 Shortest Distance (20 分) The task is really simple: given N exits on a highway which forms a si ...
- PAT 甲级 1046 Shortest Distance (20 分)(前缀和,想了一会儿)
1046 Shortest Distance (20 分) The task is really simple: given N exits on a highway which forms a ...
- PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...
- 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 ...
- 1046 Shortest Distance (20分)
The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...
- PAT (Advanced Level) 1046. Shortest Distance (20)
处理一下前缀和. #include<iostream> #include<cstring> #include<cmath> #include<algorith ...
- PAT甲题题解-1046. Shortest Distance (20)-做了一个假的最短路,水
一开始以为是最短路,结果是给你一个环,让你求环上两点之间的距离...那还做毛线 然而还是得做毛线 #include <iostream> #include <cstdio> # ...
- 【PAT甲级】1046 Shortest Distance (20 分)
题意: 输入一个正整数N(<=1e5),代表出口的数量,接下来输入N个正整数表示当前出口到下一个出口的距离.接着输入一个正整数M(<=10000),代表询问的次数,每次询问输入两个出口的序 ...
随机推荐
- Android(java)学习笔记117:英文朗诵android App编写实例
1.首先,我先把代码放到下面: package com.himi.speaker; import java.util.Locale; import android.app.Activity; impo ...
- hibernate 查询
String hql = "select * from Commodity where commodityName like :commodityname" ...
- 在vs中跑动ransac
期间遇到很多问题. 记一个最主要的是: LINK2019 无法识别的外部符号,然后某一个函数的函数名 然后是 @@函数名 (@) 大概长成这样.或者还就根本就是 无法识别的外部符号. 解决方案: 我这 ...
- CF A and B and Team Training (数学)
A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Spring AOP原理解析
原文链接请参见:http://blog.csdn.net/u010723709/article/details/47839307
- union on
UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每条 SELECT 语句中的列 ...
- Asp.net MVC 4 Html帮助类 II
Html Helpers @Html.AntiForgeryToken It generates a hidden form field (anti-forgery token) that is va ...
- 有些方法为什么会声明称static静态的
有些方法在调用的时候,没有必要都要先实例化一下,只需要:[类名. 静态方法 ]就行了. 哪些方法的调用没有必要实例化呢?网上找了个例子: 举个例子:Car类,1.静态方法Run(),Car.Run() ...
- React-Native错误笔记-EPERM
运行react-native run-android时出现错误 EPERM:operation not permitted,lstat .............. 解决办法:用Android Stu ...
- jQuery之锚点带动画跳转特效
背景图片为金木研,这是我最爱的一张图. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...