当前位置:网站首页>Pat 1046 shortest distance (20 points) simulation
Pat 1046 shortest distance (20 points) simulation
2022-07-06 02:39:00 【Python ml】
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n,m,sum=0,start,end;
cin>>n;
vector<int>a(n),dis(n+1);
for(int i=1;i<n;i++){
scanf("%d",&a[i]);
dis[i+1]=dis[i]+a[i]; //dis[i] From the starting point to the i The distance between nodes
sum+=a[i];
}
scanf("%d",&a[0]);
sum+=a[0]; //sum Is the sum of the circular journey
cin>>m;
for(int i=0;i<m;i++){
cin>>start>>end;
if(start>end) swap(start,end);
int temp=dis[end]-dis[start];
cout<<min(temp,sum-temp)<<endl;
}
return 0;
}
边栏推荐
- Li Kou today's question -729 My schedule I
- After changing the GCC version, make[1] appears in the compilation: cc: command not found
- Large scale DDoS attacks take Myanmar offline
- 【MySQL 15】Could not increase number of max_open_files to more than 10000 (request: 65535)
- How to check the lock information in gbase 8C database?
- SSM assembly
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
- Number conclusion LC skimming review - 1
- GifCam v7.0 极简GIF动画录制工具中文单文件版
- 更换gcc版本后,编译出现make[1]: cc: Command not found
猜你喜欢
淘宝焦点图布局实战
ReferenceError: primordials is not defined错误解决
3D drawing ()
Blue Bridge Cup group B provincial preliminaries first question 2013 (Gauss Diary)
高数_向量代数_单位向量_向量与坐标轴的夹角
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
如何精准识别主数据?
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
[Digital IC manual tearing code] Verilog asynchronous reset synchronous release | topic | principle | design | simulation
Keyword static
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
2345文件粉碎,文件强力删除工具无捆绑纯净提取版
【MySQL 15】Could not increase number of max_open_files to more than 10000 (request: 65535)
High number_ Vector algebra_ Unit vector_ Angle between vector and coordinate axis
Déduisez la question d'aujourd'hui - 729. Mon emploi du temps I
Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
Introduction to robotframework (III) Baidu search of webui automation
Method of changing object properties
Black high-end responsive website dream weaving template (adaptive mobile terminal)
ftp上传文件时出现 550 Permission denied,不是用户权限问题
Easy to use js script
[postgraduate entrance examination English] prepare for 2023, learn list5 words
Number conclusion LC skimming review - 1
MySQL winter vacation self-study 2022 11 (5)
Follow the mouse's angle and keyboard events
微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器
Paper notes: graph neural network gat
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
[Digital IC manual tearing code] Verilog asynchronous reset synchronous release | topic | principle | design | simulation