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 ...
随机推荐
- zabbix回顾
1.zabbix能收集哪些信息? 磁盘空间,磁盘IO,cpu负载,内存使用情况,开机时间,网卡的网络流量,进程数等 2.zabbix支持哪些通讯方式? agent:通过专用的代理程序进行监控,是mas ...
- vim中文乱码问题
问题如下: 修改 /etc/vimrc 文件 添加: ,ucs-bom,gb18030,gbk,gb2312,cp936 把/etc/vimrc复制到你自己的根目录下面:复制为.vimrc(前面有个点 ...
- Python自动发送邮件提示:smtplib.SMTPServerDisconnected: please run connect() first
参考:http://blog.csdn.net/leven_change/article/details/66976695
- 使用RStudio调试(debug)基础学习(二)和fGarch包中的garchFit函数估计GARCH模型的原理和源码
一.garchFit函数的参数--------------------------------------------- algorithm a string parameter that deter ...
- 移动端遇到的问题小结--video
本篇主要是针对Android系统,所遇到的问题. 1. video的全屏处理: 这里说的全屏是指针对浏览器的全屏,而不是整个手机的全屏.要想全屏效果只需对video标签加 webkit-plays ...
- MySQL改密码
必须先修改my.cnf 添加 skip-grant-tables 然后 执行 update mysql.user set authentication_string=password('123 ...
- ORACLE中RECORD、VARRAY、TABLE的使用详解(转)
原文地址:ORACLE中RECORD.VARRAY.TABLE的使用详解
- MHA实现MySQL的高可用
一:软件简介 MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,是一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件. 在 ...
- AJAX如何实现和后端的交互(网页如何与 web 服务器进行通信)
在这里我们将会用一个姓名提示框案例来简单说明: 当用户在输入框中键入字符时,网页与 web 服务器进行通信,服务器返回提示信息,传给网页: 先看一下界面: 在html页面中: 思路:就是当用户在上面的 ...
- HTTP Basic和Digest认证介绍与计算
一.说明 web用户认证,最开始是get提交+把用户名密码存放在客户端的cookie中的形式:在意识到这样不安全之后逐渐演变成了post提交+把用户凭证放到了服务端的session中的形式(当然ses ...