1031. Railway Tickets
The railway line “Yekaterinburg-Sverdlovsk” with several stations has been built. This railway line can be represented as a line segment, railway stations being points on it. The railway line starts at the station “Yekaterinburg” and finishes at the station “Sverdlovsk”, so stations are numbered starting from “Yekaterinburg” (it has number 1) and “Sverdlovsk” is the last station. Cost of the ticket between any two stations depends only on a distance between them. The prices for the tickets are specified in the following table.
| distance X between stations | price for the ticket |
| 0 < X ≤ L1 | C1 |
| L1 < X ≤ L2 | C2 |
| L2 < X ≤ L3 | C3 |
Input
The first line of the input contains 6 integers L 1, L 2, L 3, C 1, C 2, C 3 (1 ≤ L 1 < L 2 < L 3 ≤ 10 9, 1 ≤ C 1 < C 2 < C 3 ≤ 10 9) in the specified order with one space between. The second line contains the amount of stations N (2 ≤ N ≤ 10000). The third line contains two different integers separated by space. They represent serial numbers of stations, the travel between which must be paid. Next N−1 lines contain distances from the first station (“Yekaterinburg”) on the railway line to others. These distances are given as different positive integers and are arranged in the ascending order. The distance from “Yekaterinburg” to “Sverdlovsk” does not exceed 10 9. The distance between any neighboring stations does not exceed L 3. The minimal travel cost between two given stations will not exceed 10 9.Output
Program should print to the output the only number, which is the minimal travel cost between two given stations.Sample
| input | output |
|---|---|
3 6 8 20 30 40 7 2 6 3 7 8 13 15 23 | 70 |
1 #includeView Code2 #include<string> 3 #include 4 #include 5 #include 6 #define LL long long 7 #define L long 8 using namespace std; 9 const long inf=1<<30; 10 L L1,L2,L3,C1,C2,C3; 11 L f[10010],i,j; 12 L s,e,n; 13 L dis[10010]; 14 L judge(L d) 15 { 16 if(d<=L1&&d>0) 17 return C1; 18 if(d<=L2&&d>L1) 19 return C2; 20 if(d<=L3&&d>L2) 21 return C3; 22 } 23 int main() 24 { 25 cin>>L1>>L2>>L3>>C1>>C2>>C3; 26 cin>>n; 27 cin>>s>>e; 28 if(s>e) 29 { 30 L temp; 31 temp=s; 32 s=e; 33 e=temp; 34 } 35 for(i=2;i<=n;i++) 36 cin>>dis[i]; 37 for(i=0;i<=n;i++) 38 f[i]=inf; 39 f[s]=0; 40 for(i=s+1;i<=e;i++) 41 { 42 for(j=s;j) 43 if(dis[i]-dis[j]<=L3) 44 { 45 if(f[i]>f[j]+judge(dis[i]-dis[j])) 46 f[i]=f[j]+judge(dis[i]-dis[j]); 47 } 48 } 49 cout< endl; 50 return 0; 51 52 53 }
转载于:https://www.cnblogs.com/sdau--codeants/p/3240378.html
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
