首页 技术 正文
技术 2022年11月23日
0 收藏 463 点赞 4,159 浏览 2935 个字

Railway tickets

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2472   Accepted: 865

Description

The railway line “Ekaterinburg-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 “Ekaterinburg” and finishes at the station “Sverdlovsk”, so stations are numbered starting from “Ekaterinburg” (it has number 1) and “Sverdlovsk” is the last station. 
POJ 2355 Railway tickets
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 between stations –X

price for the ticket

0<X<=L1

C1

L1<X<=L2

C2

L2<X<=L3

C3

Direct tickets from one station to another can be booked if and only if the distance between these station does not exceed L3. So sometimes it is necessary to book several tickets to pay for the parts of the whole way between stations.

For example, on the railway line shown at the figure above there are seven stations. The direct ticket from the second station to the sixth one can not be booked. There are several ways to pay for the travel between these stations. One of them is to book two tickets: one ticket at price C2 to travel between the second and the third stations, and other at price C3 to travel between the third and the sixth stations. Note, that though the distance between the second and the sixth stations is equal to 2*L2, the whole travel can not be paid by booking two tickets at price C2, because each ticket is valid for only one travel and each travel should start and end only at stations.

Your task is to write a program, that will find the minimal cost of the travel between two given stations.

Input

The first line of the input file contains 6 integers L1, L2, L3, C1, C2, C3 (1 <= L1 < L2 < L3 <= 10^9, 1 <= C1 < C2 < C3 <= 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 (“Ekaterinburg”) on the railway line to others. These distances are given as different positive integers and are arranged in the ascending order. The distance from “Ekaterinburg” to “Sverdlovsk” does not exceed 10^9. The distance between any neighboring stations does not exceed L3. The minimal travel cost between two given stations will not exceed 10^9.

Output

Program should print to the output file the only number, which is the minimal travel cost between two given stations.

Sample Input

3 6 8 20 30 40
7
2 6
3
7
8
13
15
23

Sample Output

70
题目大意:有一个铁路线,线上有n个站,每个站之间都有一段距离,这个车站根据路程的长短出售3种票,每种票能够乘坐的距离不同,一个票只能用于从一个站到另一个站,问从站a到站b花费的最少金钱。
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
int dist[], dp[];int main()
{
int L1, L2, L3, C1, C2, C3;
int n, s, e;
scanf("%d%d%d%d%d%d", &L1, &L2, &L3, &C1, &C2, &C3);
scanf("%d", &n);
scanf("%d%d", &s, &e);
if (s > e)
{
s ^= e;
e ^= s;
s ^= e;
}
for (int i = s; i <= e; i++)
{
dp[i] = 0x7fffffff;
}
dist[] = ;
for (int i = ; i <= n; i++)
{
scanf("%d", &dist[i]);
}
dp[s] = ;
for (int i = s; i < e; i++)
{
for (int j = i + ; j <= e; j++)
{
if (dist[j] - dist[i] <= L1 && dp[j] > dp[i] + C1)
{
dp[j] = dp[i] + C1;
}
if (dist[j] - dist[i] <= L2 && dp[j] > dp[i] + C2)
{
dp[j] = dp[i] + C2;
}
if (dist[j] - dist[i] <= L3 && dp[j] > dp[i] + C3)
{
dp[j] = dp[i] + C3;
}
}
}
printf("%d\n", dp[e]);
return ;
}
 
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,156
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,624
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,468
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,240
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,876
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,043