当前位置:网站首页>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;
}边栏推荐
- Digital warehouse: iqiyi digital warehouse platform construction practice
- Gcc/g++ and dynamic and static libraries and GDB
- TI C6000 TMS320C6678 DSP+ Zynq-7045的ZYNQ PS + PL异构多核案例开发手册(1)
- 初识OpenGL (2)编译着色器
- 理解卷积神经网络中的权值共享
- OSPF comprehensive experiment
- Chapter 7 supporting CORS in rest services
- Implementation of personalized healthy diet recommendation system based on SSM
- 阿里云DMS MySQL云数据库建表报错,求解!!
- Can the parameterized view get SQL with different rows according to the characteristics of the incoming parameters? For example, here I want to use the column in the transmission parameter @field
猜你喜欢

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]

TI C6000 TMS320C6678 DSP+ Zynq-7045的ZYNQ PS + PL异构多核案例开发手册(1)

潘多拉 IOT 开发板学习(RT-Thread)—— 实验17 ESP8266 实验(学习笔记)

我们被一个 kong 的性能 bug 折腾了一个通宵

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

Refuse noise, the entry journey of earphone Xiaobai

Sklearn clustering clustering

Yushenle's learning record: the first project of SOC FPGA -hello world

基于SSM实现个性化健康饮食推荐系统
Specific practice cases of "card note taking method" in Siyuan
随机推荐
Parker solenoid valve d1vw020dnypz5
Question collection come and ask nllb authors! (Zhiyuan live issue 24)
全志A40i工业核心板,100%国产4核ARM Cortex-A7,支持“双屏异显”【显示接口能力,工业HMI首选方案】
Pandora IOT development board learning (RT thread) - Experiment 17 esp8266 experiment (learning notes)
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: aerosol daily data set from 1980 to 2022
[expdp export data] expdp exports a table with 23 rows of records and no lob field. It takes 48 minutes. Please help us have a look
parker电磁阀D1VW020DNYPZ5
《硅谷之谜》读后感
德国emg电动执行器EB800-60II
初识OpenGL (4)链接着色器
博途PLC顺序开关机功能块(SCL)
If you want to be good at work, you must first use its tools -c language expansion -- embedded C language (11)
数智转型,管理先行|JNPF全力打造“全生命周期管理”平台
kalibr标定realsenseD435i --多相机标定
Implementation of personalized healthy diet recommendation system based on SSM
A coal mine in Yangquan, Shanxi Province, suffered a safety accident that killed one person and was ordered to stop production for rectification
大型仿人机器人整机构型研究与应用
Daily1:SVM
Sklearn clustering clustering
https://github.com/ZouJiu1/PAT