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 ...
随机推荐
- mysql ----BaseDao工具类
package com.zjw.dao; import java.sql.*; /** * 工具类 */ public class BaseDao { static final String DB_U ...
- js可拖拽的div
function chatDrag(div1) { div1.onmousedown = function (ev) { var oevent = ev || event; var distanceX ...
- release环境下,当前不会命中断点,还没有为该文档加载任何符号
今天在release编译环境下出现了如标题所说的问题“ 当前不会命中断点,还没有为该文档加载任何符号”,在网上找了几个方法都没有解决我的问题,咨询了一下师傅,解决了,很简单,方法如下:右键--属性-- ...
- eclipse运行项目,tomcat报错:Exception in thread :http-bio-8080-exec-4
eclipse运行项目,tomcat报错:Exception in thread :http-bio-8080-exec-4 转自 https://www.cnblogs.com/yby-blogs/ ...
- Vue 组件异步加载(懒加载)
一.vue的编译模式 (1)路由配置信息 //eg1: const MSite = resolve => require.ensure([], () =>resolve(require([ ...
- SpringBoot使用日志
1.日志框架 日志门面 日志实现 JCL.SLF4J.jboss-logging Log4j.JUL.Log4j2.Logback 日志门面:SLF4J 日志实现:Logback SpringBoot ...
- Django中ORM介绍和字段及字段参数
Object Relational Mapping(ORM) 1 ORM介绍 1.1 ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对 ...
- LAMP环境配置安装注意安装步骤及说明事项
一.安装gcc shell># yum -y install gcc 二.安装zlib压缩库 shell>## cd /home/hsk/tar shell># tar –zxvf ...
- fiddler安装及mock数据
1,fiddler安装,解决无法抓到https问题 可用本机的火狐浏览器测试,不行,就fiddler生成证书,拷到火狐里 在firefox中,选项->进入配置界面:高级-> 证书 -> ...
- .net core 获取本地ip及request请求端口
1.获取ip和端口 string str = (Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + " ...