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),代表询问的次数,每次询问输入两个出口的序 ...
随机推荐
- 用CCRenderTexture和BlendFunc制作游戏教学时使用的黑色覆盖层
游戏快要完成了,准备做教学. 我们的教学是在整个界面上盖一层灰色图片,然后把提示点击的按钮部分亮出来,也就是在一块黑色图片上,按需求扣空一小部分.如图,把武器部分扣空,那么在其它地方又会扣空其它部分, ...
- css笔记03:伪类first-child
1. 匹配第一个 <p> 元素 在下面的例子中,选择器匹配作为任何元素的第一个子元素的 p 元素: <html> <head> <style type=&qu ...
- Hummer框架平台介绍
三年工作过程中经常会用到使用Java开源框架,但经常会遇到重新组合比较麻烦,本次采用目前主流开源框架及插件整理出一套融合开发.测试.部署整个流程的平台. 本平台采用Hummer代号,是悍马和蜂鸟分意思 ...
- PHP--关于模板的原理和解析
此内容用作笔记,以备日后查看,此内容为学习李炎恢课程而来,并非自己所创,如有问题请私信~ 将PHP代码和静态HTML代码进行分离,使代码的可读性和维护性得到显著提高. 使用模板引擎: 我们所说的模板是 ...
- LeetCode 61
Rotate List Given a list, rotate the list to the right by k places, where k is non-negative. For exa ...
- poj 3159 差分约束
思路:班长的糖果要比snoopy的多.并且要用手写堆栈,且堆栈的大小要开到20000000. #include<iostream> #include<cstdio> #incl ...
- 转: Android开发中的MVP架构详解(附加链接比较不错)
转: http://www.codeceo.com/article/android-mvp-artch.html 最近越来越多的人开始谈论架构.我周围的同事和工程师也是如此.尽管我还不是特别深入理解M ...
- jQuery选择器容易忽视的小知识大问题
1 关于检查某个元素在网页上的存在 很多人会惯性的写成 } 其实应该根据获取到元素的长度来判断 if($("#tt").length>0){ //do something博 ...
- Jersey(1.19.1) - Sub-resources
@Path may be used on classes and such classes are referred to as root resource classes. @Path may al ...
- Java之绘制方法
绘制图形所用的函数类别分别为视图类.图形单元类和页面类. 对视图类,设置窗口的位置和大小: 对图形单元类,设置图形边界: 对页面类,只有当页面作为元件,该函数才起作用,设置元件边界. 一般构建窗口我们 ...