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 ...
随机推荐
- transform:rotate3d/tranlate3d
transform:rotate3d(x,y,z,angle); rotate3d 代表 在3D空间,元素沿着 经过原点(0,0,0) 和 三维坐标(x,y,z) 2点的直线进行旋转.其中: x:是一 ...
- poj2528 Mayor's posters (线段树+离散化)
恩,这区间范围挺大的,需要离散化.如果TLE,还需要优化一下常数. AC代码 #include <stdio.h> #include <string.h> #include & ...
- Linux之DHCP搭建命令集锦
systemctl start dhcpd //启动DHCP systemctl enable dhcpd //配置服务开机启动 ps aux | grep ...
- 使用JSR-303进行校验
package com.ieou.comac.module.web.dto.employee; import lombok.Data; import javax.validation.constrai ...
- Flume+Sqoop+Azkaban笔记
大纲(辅助系统) 离线辅助系统 数据接入 Flume介绍 Flume组件 Flume实战案例 任务调度 调度器基础 市面上调度工具 Oozie的使用 Oozie的流程定义详解 数据导出 sqoop基础 ...
- Hadoop OutputCommitter
1. OutputCommitters MapReduce使用一个提交协议来确保作业(job)和任务(task)都完全成功或失败.这个通过 OutputCommiter来实现. 新版本 MapRedu ...
- 站在Web3.0 理解IPFS是什么
尽管网络上,已经有不少文章讨论IPFS,不过真正讲明白IPFS想做什么的很少,文本尝试站在未来Web3.0的高度来看看IPFS究竟用来解决什么问题. DApp 的缺陷 对区块链有所了解的同学,知道区块 ...
- ImageWatch 无法安装在VS2017环境下的解决方案
Download: https://marketplace.visualstudio.com/items?itemName=VisualCPPTeam.ImageWatch#qna For Visua ...
- oracle 夸服务器、数据库查询
create public database link 连接名 connect to 需要连接数据库名 identified by 需要连接数据库密码 USING '(DESCRIPTION = ...
- Wincc报表+Listview使用
listview在Wincc中可以作为显示的控件,对于列表表头的定义如下所示: list的命名,点击属性,在对象名称中对其定义: 有了listview的定义,就可以使用VBS对其表头的定义.具体代码如 ...