【PAT甲级】1046 Shortest Distance (20 分)
题意:
输入一个正整数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 分)的更多相关文章
- 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 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) Practice 1046 Shortest Distance (20 分) 凌宸1642
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...
- 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) 2016-09-09 23:17 22人阅读 评论(0) 收藏
1046. Shortest Distance (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
- PAT 甲级 1046 Shortest Distance
https://pintia.cn/problem-sets/994805342720868352/problems/994805435700199424 The task is really sim ...
- 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 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
随机推荐
- Linux 中查看可用的网络接口
目录 Linux 中查看可用的网络接口 在 Linux 中找到可用的网络接口 title: Linux 中查看可用的网络接口 date: 2020/2/25 16:56:36 toc: true -- ...
- 如何在IntelliJ Idea中同时启动不同端口的两个实例
在SpringCloud开发过程中需要在一个项目中启用不同的端口,我使用的工具是IDEA 步骤1 创建SpringBoot工程 步骤2 在配置文件中添加如下配置: spring.application ...
- 第十七篇 Linux下常用命令汇总
- spring_boot 中通过PageHelper分页
1. 第一步 导入pom.xml依赖 <!--PageHelper模版--> <!--PageHelper模版--> <dependency> <groupI ...
- casperJs的安装2
通过上面一节,以为能够顺利安装好phantom 没想到,根本没成功. 接着,通过github上下载项目,重新安装: 1.clone项目:[https://github.com/ariya/phanto ...
- hibernate和mybatis出现配置文件xml的文件报错Multiple annotations found at this line(转)
hibernate中的xml配置文件Multiple annotations found at this line,出现这个红叉报错,直接是把 <?xml version="1.0&q ...
- ubuntu更换pip源
1.创建pip.conf文件 cd ~/.pip 当提示不存在时,创建它 mkdir ~/.pip 在.pip目录下创建一个pip.conf文件 touch pip.conf 2.编辑pip.conf ...
- 使用Canvas画布的注意事项
1.开始一个路径时要使用beiginPath()方法 ,不然会发生意想不到的事件. 2.图片加载完成后才能按照顺序依次绘图 (巧用onload时间)
- JS-禁用浏览器前进后退
使用jQuery: <script type="text/javascript" language="javascript"> $(document ...
- GO学习之 为什么选择GO
一.Go语言为并发而生 如上所述,硬件制造商正在为处理器添加越来越多的内核以提高性能.所有数据中心都在这些处理器上运行,更重要的是,今天的应用程序使用多个微服务来维护数据库连接,消息队列和维护缓存.因 ...