题意:

输入一个正整数N(<=1e5),代表出口的数量,接下来输入N个正整数表示当前出口到下一个出口的距离。接着输入一个正整数M(<=10000),代表询问的次数,每次询问输入两个出口的序号,输出他们之间的最小距离。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int dis[],sum[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=;i<=n;++i){
cin>>dis[i];
sum[i]=sum[i-]+dis[i];
}
int q;
cin>>q;
for(int i=;i<=q;++i){
int u,v;
cin>>u>>v;
if(v<u)
swap(u,v);
int x=sum[v-]-sum[u-];
int y=sum[n]-x;
cout<<min(x,y)<<"\n";
}
return ;
}

【PAT甲级】1046 Shortest Distance (20 分)的更多相关文章

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

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

  2. 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 ...

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

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

  4. 1046 Shortest Distance (20 分)

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

  5. 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 ...

  6. PAT 甲级 1046 Shortest Distance

    https://pintia.cn/problem-sets/994805342720868352/problems/994805435700199424 The task is really sim ...

  7. 1046 Shortest Distance (20分)

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

  8. PAT 甲级 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

  9. PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

随机推荐

  1. 微信小程序 购物车流程

    购物车流程 一.需求分析 a:全选,单选,根据选中的计算数目和总价 b:单个商品加减 c:删除一个商品 wxml 布局 <view> <view v-if="flag&qu ...

  2. springboot08(springmvc自动配置原理)

    MVC WebMvcAutoConfiguration.java @ConditionalOnMissingBean(name = "viewResolver", value = ...

  3. 喵星之旅-狂奔的兔子-基于docker的rabbitmq安装

    docker安装参考:喵星之旅-狂奔的兔子-docker安装和基本使用 一.查询镜像名称 由于我们要安装的是有web管理页面的,不能直接拉取,需要指定版本. 登录docker仓库查询:https:// ...

  4. vs查看动态库依赖

    dumpbin是VS自带的工具,进入Visual Studio 的命令提示 查看程序或动态库所依赖的动态库 dumpbin /dependents  abc.exe 查看动态库的输出函数 dumpbi ...

  5. 【音乐欣赏】《Fake》 - The Tech Thieves

    曲名:Fake 作者:The Tech Thieves [01;12.092]I got wasted,learning how to let it out [01;24.009]Please don ...

  6. Go递归函数

    package main import "fmt" func main() { /* 递归函数(recursion):一个函数自己调用自己,就叫做递归函数. 递归函数要有一个出口, ...

  7. Subroutine 子程序 Perl 第四章

    子程序的定义是全局的,不需要事先声明.若重复定义子程序,后面的覆盖前面的. sub marine { $n +=1; print " Hello ,sailor number $_ ! &q ...

  8. Python环境搭建后,多种方式的使用进行程序的执行。

    Python环境搭建后,可以使用多种方式进行程序的执行. 第一种: 进入CMD命令提示符 输入python 进入python环境(可以使用Ctrl+C退出) 输入print("hello&q ...

  9. Error: EACCES: permission denied, open '/Users/qinmengjiao/WebstormProjects/m-kbs-app/.babelrc

    表示没有访问这个文件的权限 执行命令 sudo chown -R $(whoami) ~/WebstormProjects/m-kbs-app/.babelrc 就可以解决上面的问题 以下是chown ...

  10. 如何使用git和github

    转载:https://www.cnblogs.com/cxscode/p/8325064.html 如何用git将项目代码上传到github 先上常用语句 git add . git commit - ...