PAT A1046 Shortest Distance
PAT A1046 Shortest Distance
标签(空格分隔): PAT
TIPS: 最后一个数据点可能会超时
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 100010;
int d[maxn], dist[maxn];
int main() {
int total = 0, n;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", &d[i]);
total += d[i];
dist[i] = total;
}
int m;
int start, end;
scanf("%d", &m);
for(int i = 0; i < m; i++) {
scanf("%d%d", &start, &end);
if(start > end) swap(start, end);
int temp = dist[end - 1 ] - dist[start - 1];
printf("%d\n", min(temp, total - temp));
}
return 0;
}
PAT A1046 Shortest Distance的更多相关文章
- PAT A1046 Shortest Distance (20 分)
题目提交一直出现段错误,经过在网上搜索得知是数组溢出,故将数组设置的大一点 AC代码 #include <cstdio> #include <algorithm> #defin ...
- PAT甲级——A1046 Shortest Distance
The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...
- A1046. Shortest Distance
The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...
- PAT 1046 Shortest Distance
1046 Shortest Distance (20 分) The task is really simple: given N exits on a highway which forms a ...
- PAT 1046 Shortest Distance[环形][比较]
1046 Shortest Distance(20 分) The task is really simple: given N exits on a highway which forms a sim ...
- A1046 Shortest Distance (20)(20 分)
1046 Shortest Distance (20)(20 分)提问 The task is really simple: given N exits on a highway which form ...
- pat 1046 Shortest Distance(20 分) (线段树)
1046 Shortest Distance(20 分) The task is really simple: given N exits on a highway which forms a sim ...
- A1046. Shortest Distance(20)
17/20,部分超时. #include<bits/stdc++.h> using namespace std; int N,x,pairs; int a,b; vector<int ...
- PAT——甲级1046S:shortest Distance
这道题,折磨了我一个多小时,前前后后写了三个算法. 1046 Shortest Distance (20 point(s)) The task is really simple: given N ex ...
随机推荐
- 数据结构与算法(C#)入门 --- 线性表
线性表: 线性表是最简单,最基本,最常用的数据结构.线性表中的数据元素之间存在一对一的关系.即:除了第一个元素,其他元素前面有且只有一个元素:除了最后一个元素,其他元素后面有且只有一个元素.生活中的例 ...
- Web API系列(三) 异常处理
在上一篇教程中我为大家介绍了Web API中Filter的开发使用,其中讲到ExceptionFilter时留了一个坑:ExceptionFilter只能截获并处理Action执行过程中发生的异常,在 ...
- scss、sass、less的对比与区别
什么是Sass和Less? sass和less都属于CSS预处理器. css预处理定义了一种新的语言,其基本思想是,用一种专门的编程语言,为css增加了一些编程的特性,将CSS作为目标生成文件,然后开 ...
- ssh整合oracle数据源报错????
在SSH整合的时候,引入oracle的pom节点,但是报错,因为没有权限,要手动将Oracle.jar注册到本地仓库 保证你电脑有maven环境,测试 方式为 cmd---->mvn -vers ...
- 关于li标签的value属性值的获取问题
在前几天的开发过程中,遇到了这样一个问题. 在li标签中嵌入了一个value属性,如这样滴: <li id="ts1" value="0001">& ...
- 学习笔记77—Iphone集
****************************************************** 如有谬误,请联系指正.转载请注明出处. 联系方式: e-mail: heyi9069@gm ...
- 学习笔记70—Photoshop画齿轮
具体步骤如下: 1)选择多边形工具: 2)设置齿轮个数及颜色相应参数: 3)画出模型: 4)找到上图模型的中心 (借助:ctrl + T),选择椭圆工具,并 长按Shift+Alt, 画出圆: 5) ...
- Docker五大优势:持续集成、版本控制、可移植性、隔离性和安全性
随着Docker技术的不断成熟,越来越多的企业开始考虑使用Docker.Docker有很多的优势,本文主要讲述了Docker的五个最重要优势,即持续集成.版本控制.可移植性.隔离性和安全性. 对于Do ...
- 开发者的自测利器-Hprof命令(寻找cpu热点)
测试代码: public class HProfTest { public void slowMethod() { try { Thread.sleep(1000); } catch (Excepti ...
- python webdriver api-对启动的火狐浏览器添加配置
Webdriver启用的火狐不带插件,可以自已进行配置 先找到火狐的安装路径 C:\Program Files\Mozilla Firefox 步骤说明 在CMD中使用cd命令进入firefox.ex ...