当前位置:网站首页>PAT甲级 1046 Shortest Distance
PAT甲级 1046 Shortest Distance
2022-07-26 15:55:00 【九是否非随机的称呼】
#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;
}边栏推荐
- 博途PLC顺序开关机功能块(SCL)
- Using information entropy to construct decision tree
- TI C6000 TMS320C6678 DSP+ Zynq-7045的PS + PL异构多核案例开发手册(2)
- 2022年最新西藏建筑施工架子工(建筑特种作业)模拟考试试题及答案
- 泰山OFFICE技术讲座:WORD的缩放比例与显示略有差异
- Quanzhi a40i industrial core board, 100% domestic 4-core arm cortex-a7, supports "dual screen abnormal display" [display interface capability, preferred scheme for industrial HMI]
- hawe螺旋插装式单向阀RK4
- 物联网工业级串口转WiFi转网口转以太网模块的选型
- 阿里云DMS MySQL云数据库建表报错,求解!!
- JVM 的类初始化机制
猜你喜欢

一文详解 Redis 中 BigKey、HotKey 的发现与处理

Quanzhi a40i industrial core board, 100% domestic 4-core arm cortex-a7, supports "dual screen abnormal display" [display interface capability, preferred scheme for industrial HMI]

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

My brother created his own AI anti procrastination system, and he was "blinded" when playing with his mobile phone | reddit was hot

Parker solenoid valve d1vw020dnypz5

测试用例千万不能随便,记录由一个测试用例异常引起的思考

全志A40i工业核心板,100%国产4核ARM Cortex-A7,支持“双屏异显”【显示接口能力,工业HMI首选方案】

基于SSM开发实现校园疫情防控管理系统

VS2019Debug模式太卡进不去断点
随机推荐
Zynq PS + PL heterogeneous multicore Case Development Manual of Ti C6000 tms320c6678 DSP + zynq-7045 (1)
【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)
认识JS基础与浏览器引擎
We were tossed all night by a Kong performance bug
基于NoCode构建简历编辑器
理解卷积神经网络中的权值共享
parker电磁阀D1VW020DNYPZ5
hawe螺旋插装式单向阀RK4
German EMG electric actuator eb800-60ii
初识OpenGL (3)片段着色器(Fragment Shader)
什么是GPIO,它有什么用
gcc/g++与动静库以及gdb
PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (3)
泰山OFFICE技术讲座:WORD的缩放比例与显示略有差异
剑指offer专项突击版第11天
kalibr标定realsenseD435i --多相机标定
技术风向标 | 云原生技术架构成熟度模型解读
ROS problems and Solutions - relying on package installation and unable to correct errors
[tool sharing] automatic generation of file directory structure tool mddir
Is it safe for CICC fortune to speculate in stocks? The securities company with the cheapest handling fee
https://github.com/ZouJiu1/PAT