九度OJ 1086 清华大学2011年机试 《最小花费》

#include <iostream>
#include <stdio.h>
using namespace std;
#define MAX 2100000000000

long long int dist[10000];
long long int cost[10000];
	
int main()
{
	long long int L1,L2,L3,C1,C2,C3;
		
	while(scanf("%lld%lld%lld%lld%lld%lld",&L1,&L2,&L3,&C1,&C2,&C3)!=EOF)
<span style="white-space:pre">	</span>{
	<span style="white-space:pre">	</span>long long int A = 0,B = 0;
		long long int N = 0;
		long long int i,j,t;
		cin>>A>>B;
		cin>>N;
				
		for(t = 2; t <= N;t++)
			cin>>dist[t];//输入到第二站,第三站... ...第N站的距离
		dist[0] = dist[1] = 0;
				
		if( A > B ){  //如果A>B,交换A,B
			int temp = A;  
			A = B;  
			B = temp;  
		}

		for(i = B;i >= A+1;i--)//计算出两两站之间的距离,dist[i]表示第i-1站到第i站的距离
		{                     //到第i站的花费初始化为MAX,无穷大
			dist[i] = dist[i]-dist[i-1];
			cost[i] = MAX;
		}
		cost[A] = 0;//A是起始站,在起始站花费为0
		for(i = A+1;i <= B; i++)
		{
			long long int len = 0,tmp = 0;
			for(j = i-1; j >= A;j--)
			{
				len += dist[j+1];//len为起始站到第i-1站的距离
				if(len <= L1)   //0<len<=L1,花费为C1;L1<len<=L2,花费为C2;L2<len<=L3,花费为C3
					tmp = C1;
				else if(len <= L2)
					tmp = C2;
				else if(len <=L3)
					tmp = C3;
				else 
	<span style="white-space:pre">	</span>			break;//距离超过L3后,下车再买一张票
				if(cost[i] > cost[j] + tmp)
					cost[i] = cost[j] + tmp;				
			}		
		}
		printf("%lld\n",cost[B]);
	}

	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值