当前位置:网站首页>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;
}
边栏推荐
- 球面透镜与柱面透镜
- PMP每日一练 | 考试不迷路-7.5
- 零基础自学STM32-野火——GPIO复习篇——使用绝对地址操作GPIO
- HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
- PMP practice once a day | don't get lost in the exam -7.5
- DDoS attacks - are we really at war?
- 零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器
- [Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
- What should we pay attention to when using the built-in tool to check the health status in gbase 8C database?
- Building the prototype of library functions -- refer to the manual of wildfire
猜你喜欢

Solution: attributeerror: 'STR' object has no attribute 'decode‘

Universal crud interface

ReferenceError: primordials is not defined错误解决

力扣今日题-729. 我的日程安排表 I
![[matlab] access of variables and files](/img/cf/6f3cfdc4310fcf0bdcaa776d68261e.jpg)
[matlab] access of variables and files

Shell script updates stored procedure to database

2345 file shredding, powerful file deletion tool, unbound pure extract version

Introduction to robotframework (I) brief introduction and use
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17](/img/85/2635afeb2edeb0f308045edd1f3431.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17

"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
随机推荐
3D drawing ()
sql表名作为参数传递
纯Qt版中国象棋:实现双人对战、人机对战及网络对战
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
剑指 Offer 30. 包含min函数的栈
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
在GBase 8c数据库中使用自带工具检查健康状态时,需要注意什么?
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
Looking at the trend of sequence modeling of recommended systems in 2022 from the top paper
Keyword static
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
Accident index statistics
Maturity of master data management (MDM)
MySQL winter vacation self-study 2022 11 (5)
RobotFramework入门(一)简要介绍及使用
07 singleton mode
PMP practice once a day | don't get lost in the exam -7.5
[matlab] access of variables and files
Bigder:34/100 面试感觉挺好的,没有收到录取