您的位置:首页 > 大数据 > 人工智能

1031. Railway Tickets

2013-08-06 13:38 375 查看
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.

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define L long
using namespace std;
const long inf=1<<30;
L L1,L2,L3,C1,C2,C3;
L  f[10010],i,j;
L s,e,n;
L dis[10010];
L judge(L d)
{
if(d<=L1&&d>0)
return C1;
if(d<=L2&&d>L1)
return C2;
if(d<=L3&&d>L2)
return C3;
}
int main()
{
cin>>L1>>L2>>L3>>C1>>C2>>C3;
cin>>n;
cin>>s>>e;
if(s>e)
{
L temp;
temp=s;
s=e;
e=temp;
}
for(i=2;i<=n;i++)
cin>>dis[i];
for(i=0;i<=n;i++)
f[i]=inf;
f[s]=0;
for(i=s+1;i<=e;i++)
{
for(j=s;j<i;j++)
if(dis[i]-dis[j]<=L3)
{
if(f[i]>f[j]+judge(dis[i]-dis[j]))
f[i]=f[j]+judge(dis[i]-dis[j]);
}
}
cout<<f[e]<<endl;
return 0;

}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: