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),代表询问的次数,每次询问输入两个出口的序 ...
随机推荐
- poj1328解题报告(贪心、线段交集)
POJ 1328,题目链接http://poj.org/problem?id=1328 题意: 有一海岸线(x轴),一半是陆地(y<0).一半是海(y>0),海上有一些小岛(用坐标点表示P ...
- 第一节:Maven 下载,安装和配置
Maven是Apache的一个产品所以要下载Maven的话可以到https://www.apache.org网站上下载 进入到APache这个网站后看一下几部操作 第一: 选择点击导航栏上面的proj ...
- App Thinning
App Thinning 由于项目中需要开启Bitcode编译,之前对Bitcode也有些误区,故整理了下相关知识,仅供参考,如有不对,还请指出. 当前 iOS App 的编译打包方式是把适配兼容多个 ...
- C# 截图类
注意修改命名空间using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { ...
- Jersey(1.19.1) - Building URIs
A very important aspects of REST is hyperlinks, URIs, in representations that clients can use to tra ...
- POi写入大批量数据
直接贴代码: package jp.co.misumi.mdm.batch.common.jobrunner; import java.io.File; import java.io.FileNotF ...
- c#中网络异常的处理办法
加入try catch来判断,catch使用的WebException来处理 try { var request = WebRequest.Create(uri); using (var respon ...
- ios自动滚动图片功能源码
源码AdScrollerView,一个已经封装好的UIScrollView的子类,可以自动滚动图片以及对应的描述语,类似淘宝app首页的广告滚动效果.滚动图片数量不限,并且显示pageControl. ...
- oracle的to_number、to_char、to_date用法
TO_DATE 是把字符串转换为数据库中得日期类型转换函数TO_CHAR 是把日期或数字转换为字符串TO_NUMBER 将字符转化为数字 TO_DATE使用TO_DATE函数将字符转换为日期TO_DA ...
- Cocos移植到Android-Android.mk编译文件
我们在上一篇博客中年使用的cocos工具对于C和C++源代码进行编译.事实上cocos工具读取<游戏工程目录>\proj.android\jni\目录中的Android.mk文件,进行交叉 ...