当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Formatting occurs twice when vs code is saved
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
好用的 JS 脚本
Déduisez la question d'aujourd'hui - 729. Mon emploi du temps I
The third level of C language punch in
剑指 Offer 29. 顺时针打印矩阵
[Digital IC manual tearing code] Verilog asynchronous reset synchronous release | topic | principle | design | simulation
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
Universal crud interface
随机推荐
Black high-end responsive website dream weaving template (adaptive mobile terminal)
更换gcc版本后,编译出现make[1]: cc: Command not found
Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
Keyword static
Force buckle 146 LRU cache
Spherical lens and cylindrical lens
深度解析链动2+1模式,颠覆传统卖货思维?
MySQL winter vacation self-study 2022 11 (5)
2020.02.11
大厂镜像库
Li Kou today's question -729 My schedule I
Zero foundation self-study STM32 - Review 2 - encapsulating GPIO registers with structures
sql表名作为参数传递
一位博士在华为的22年
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
UE4 - how to make a simple TPS role (I) - create a basic role
剑指 Offer 29. 顺时针打印矩阵
Template_ Find the reverse pair of permutations_ Sort based on merge
Formatting occurs twice when vs code is saved
Data preparation