当前位置:网站首页>Pat grade a 1046 shortest distance
Pat grade a 1046 shortest distance
2022-07-26 16:11:00 【IX. is it a non random title】
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main(void){
int i, j, k, m, n, h, mm, nn;
cin>>m;
vector<int> exits, allexit, cumsum;
exits.resize(m + 1);
cumsum.resize(m + 1);
cumsum[0] = 0;
for(i=1; i<=m; i++){
cin>>n;
exits[i] = n;
cumsum[i] = n + cumsum[i - 1];
}
cin>>m;
for(i=1; i<=m; i++){
cin>>n>>h;
allexit.push_back(n);
allexit.push_back(h);
}
int minmin, maxmax, tmp, tmp0, tmp00, sizes;
sizes = exits.size();
for(i = 0; i < m; i++){
mm = allexit[2 * i];
nn = allexit[2 * i + 1];
maxmax = max(mm, nn);
minmin = min(mm, nn);
tmp = cumsum[maxmax - 1] - cumsum[minmin - 1];
tmp0 = cumsum[sizes - 2] - cumsum[maxmax - 1] + exits[sizes - 1];
tmp00 = cumsum[minmin - 1];
tmp = min(tmp, tmp0 + tmp00);
cout<<tmp<<endl;
}
return 0;
}边栏推荐
- Encryption model
- 13 years of senior developers share a year of learning rust experience: from the necessary bibliography to code practice
- 2022 test questions and answers for the latest national fire facility operator (senior fire facility operator)
- [physical simulation] ultra simple shape matching simulates rigid body motion
- Summary of QT plug-in development -- add plug-in menu in the main interface
- FTP协议
- First knowledge of OpenGL (2) compilation shaders
- Sql语句——单行注释与多行注释
- Clojure 运行原理之编译器剖析
- 一款可视化浏览器历史的 Firefox/Chrome 插件
猜你喜欢

Botu PLC Sequential switch function block (SCL)

Development and implementation of campus epidemic prevention and control management system based on SSM

PAT甲级 1050 String Subtraction

Implementation of SAP ABAP daemon
Specific practice cases of "card note taking method" in Siyuan

Paper: all models are wrong, but many are useful: all models are wrong, but many are useful: understand the importance of variables by studying a whole class of prediction models at the same time

Google Earth Engine——MERRA-2 M2T1NXAER:1980-2022年气溶胶逐日数据集

一文详解 Redis 中 BigKey、HotKey 的发现与处理
![[tool sharing] automatic generation of file directory structure tool mddir](/img/bc/1071c0dfb20d16f5fdde641092c1af.png)
[tool sharing] automatic generation of file directory structure tool mddir

基于SSM开发实现校园疫情防控管理系统
随机推荐
The solution to the display disorder of several events files in the tensorboard
Development daily summary (11): file upload function improvement: Chinese character detection and text content processing
马斯克被曝绿了谷歌创始人:导致挚友二婚破裂,曾下跪求原谅
ROS problems and Solutions - relying on package installation and unable to correct errors
八叉树建立地图并实现路径规划导航
zabbix 6.2.0部署
请问一下各位大佬,mysql-cdc建表如何指定表的字符集呢,在官网没找到相应的连接器参数。我读一个
SAP ABAP 守护进程的实现方式
FTP协议
hawe螺旋插装式单向阀RK4
Research and application of the whole configuration of large humanoid robot
6种方法帮你搞定SimpleDateFormat类不是线程安全的问题
First knowledge of OpenGL (3) fragment shader
Understanding weight sharing in convolutional neural networks
潘多拉 IOT 开发板学习(RT-Thread)—— 实验17 ESP8266 实验(学习笔记)
Kalibr calibration realsensed435i -- multi camera calibration
Build resume editor based on Nocode
js 对数组操作的 API 总结
Botu PLC Sequential switch function block (SCL)
Modify the password of the root user of MySQL database