Circle Line
来源:互联网 发布:淘宝店怎么引流 编辑:程序博客网 时间:2024/05/13 07:32
Description
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
- d1 is the distance between the1-st and the 2-nd station;
- d2 is the distance between the2-nd and the 3-rd station;
...
- dn - 1 is the distance between then - 1-th and the n-th station;
- dn is the distance between then-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numberss and t.
Input
The first line contains integer n (3 ≤ n ≤ 100) — the number of stations on the circle line. The second line containsn integers d1, d2, ..., dn (1 ≤ di ≤ 100) — the distances between pairs of neighboring stations. The third line contains two integerss and t (1 ≤ s, t ≤ n) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output
Print a single number — the length of the shortest path between stations numbers and t.
Sample Input
42 3 4 91 3
5
45 8 2 1004 1
15
31 1 13 1
1
331 41 591 1
0
Hint
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path3 → 2 → 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int a[110];int main(){ int n,sum1,sum2,s,t,ans,i; a[0]=0; while(cin>>n){ sum1=0; sum2=0; for(i=1;i<=n;i++){ scanf("%d",&a[i]); } scanf("%d %d",&s,&t); if(s==t){ cout<<"0"<<endl; } else{ for(i=s;;i++){ if(i==t){ break; } if(i==n+1){ i=0; } sum1+=a[i]; } for(i=t;;i++){ if(i==s){ break; } if(i==n+1){ i=0; } sum2+=a[i]; } ans=min(sum1,sum2); cout<<ans<<endl; } } return 0;}
- Circle Line
- A. Circle Line
- CF 278A Circle Line
- Codeforce Circle Line 环形数据操作
- CG : Draw Line And Draw Circle
- 繪圖(line、rectangle、circle、ellipse、polylines、putText)
- 繪圖(line、rectangle、circle、ellipse、polylines、putText)
- Hough Translation & Line Detection & Circle Detection
- ellipse(),circle(),fillPoly(),line()函数介绍
- Bresenham's line and circle algorithm
- OpenCV Tutorial: 繪圖(line、rectangle、circle、ellipse、polylines、putText)
- VB绘图PSet、Line、Circle和坐标定位Scale
- circle ``
- Circle
- circle
- CCDrawingPrimitives(使用gl原始方法 绘制Points Line Rect Poly Circle Bezier CatmullRom CardinalSpline。。。。)
- SVG 形状元素(rect、circle、ellipse、line、polyline、polygon、path)
- 【opencv学习之十八】基本绘图工具line circle rectangle ellipse等
- Caffe学习系列(13):数据可视化环境(python接口)配置
- UIApplication总结
- Android中使用DrawerLayout的注意点
- Caffe学习系列(14):初识数据可视化
- NDK编译中的一些问题记录
- Circle Line
- Mysql学习总结(5)——MySql常用函数大全讲解
- Java对象的序列化和反序列化
- Openfire 的安装步骤和配置
- 第三章:通话连接的作用以及建立过程之四GsmCallTracker.java与RIL.java交互完成物理拨号
- Android图文混排-实现EditText图文混合插入上传
- java list的用法
- 基于XMPP协议的aSmack源码分析(链接)
- 网络基本知识