hdu 1690 Bus System

12 篇文章 0 订阅

wa到死才发现inf太小了,10的10次方都不是够的!

#include<iostream>
#include<cmath>
#include<algorithm>
#define maxn 110
#define ll long long
using namespace std;
ll l1,l2,l3,l4,c1,c2,c3,c4;
int n,m;
ll sta[maxn];
ll dp[maxn][maxn];
int casee=1;
ll inf=1000000000000;
ll judge(int x,int y)
{
	ll price=abs(sta[x]-sta[y]);
	if(price>0&&price<=l1)
	{
	 	return c1;
	}
	if(price>l1&&price<=l2)
	{
		return c2;
	}
	if(price>l2&&price<=l3)
	{
	    return c3;
	}
	if(price>l3&&price<=l4)
	{
	    return c4;
	}
	return inf;
}
void init()
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++) dp[i][j]=inf;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			ll price=judge(i,j);
			dp[i][j]=price;
			dp[j][i]=price;
		}
	}
}
void input()
{
	cin>>l1>>l2>>l3>>l4>>c1>>c2>>c3>>c4;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>sta[i]; 
	}
}
void solve()
{
	cout<<"Case "<<casee++<<":"<<endl;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y; 
		if(dp[x-1][y-1]!=inf)
		cout<<"The minimum cost between station "<<x<<" and station "<<y<<" is "<<dp[x-1][y-1]<<"."<<endl;
		else cout<<"Station "<<x<<" and station "<<y<<" are not attainable."<<endl;
	}
}
void flo()
{
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				//if(dp[i][k]!=inf&&dp[k][j]!=inf)
				dp[i][j]=min(dp[i][k]+dp[k][j],dp[i][j]);
				//cout<<dp[i][j]<<endl;
			}
		}
	}
	for(int i=0;i<n;i++) dp[i][i]=0;
}
int main()
{
	//cin.sync_with_stdio(false);
	int t;
	cin>>t;
	//cout<<inf<<"~"<<endl;
	while(t--)
	{

		input();
		init();
		flo();
		solve();	
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值