Bus System

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6082    Accepted Submission(s): 1560

Problem Description
Because of the huge population of China, public transportation is very important. Bus is an important transportation method in traditional public transportation system. And it’s still playing an important role even now.
The bus system of City X is quite strange. Unlike other city’s system, the cost of ticket is calculated based on the distance between the two stations. Here is a list which describes the relationship between the distance and the cost.

Your neighbor is a person who is a really miser. He asked you to help him to calculate the minimum cost between the two stations he listed. Can you solve this problem for him?
To simplify this problem, you can assume that all the stations are located on a straight line. We use x-coordinates to describe the stations’ positions.

 
Input
The input consists of several test cases. There is a single number above all, the number of cases. There are no more than 20 cases.
Each case contains eight integers on the first line, which are L1, L2, L3, L4, C1, C2, C3, C4, each number is non-negative and not larger than 1,000,000,000. You can also assume that L1<=L2<=L3<=L4.
Two integers, n and m, are given next, representing the number of the stations and questions. Each of the next n lines contains one integer, representing the x-coordinate of the ith station. Each of the next m lines contains two integers, representing the start point and the destination.
In all of the questions, the start point will be different from the destination.
For each case,2<=N<=100,0<=M<=500, each x-coordinate is between -1,000,000,000 and 1,000,000,000, and no two x-coordinates will have the same value.
 
Output
For each question, if the two stations are attainable, print the minimum cost between them. Otherwise, print “Station X and station Y are not attainable.” Use the format in the sample.
 
Sample Input
2
1 2 3 4 1 3 5 7
4 2
1
2
3
4
1 4
4 1
1 2 3 4 1 3 5 7
4 1
1
2
3
10
1 4
 
Sample Output
Case 1:
The minimum cost between station 1 and station 4 is 3.
The minimum cost between station 4 and station 1 is 3.
Case 2:
Station 1 and station 4 are not attainable.
 
Source
 
Recommend
wangye   |   We have carefully selected several similar problems for you:  2722 1689 2433 2482 2923 
 

简单最短路径,注意是64位:

 //125MS     288K    1415B     G++
#include<stdio.h>
#include<string.h>
#define N 105
#define inf 1000000000000LL
__int64 g[N][N];
int n,m;
__int64 abs(__int64 a)
{
return a<?-a:a;
}
__int64 Min(__int64 a,__int64 b)
{
return a<b?a:b;
}
void floyd() //弗洛伊德算法
{
for(int k=;k<n;k++)
for(int i=;i<n;i++)
for(int j=;j<n;j++)
g[i][j]=Min(g[i][j],g[i][k]+g[k][j]);
}
int main(void)
{
int t,k=;
__int64 l1,l2,l3,l4,c1,c2,c3,c4,x[N];
int a,b;
scanf("%d",&t);
while(t--)
{
scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&l1,&l2,&l3,&l4,&c1,&c2,&c3,&c4);
scanf("%d%d",&n,&m);
for(int i=;i<n;i++) scanf("%I64d",&x[i]);
for(int i=;i<n;i++)
for(int j=;j<n;j++){
int L=abs(x[i]-x[j]);
if(L==) g[i][j]=;
else if(L<=l1) g[i][j]=c1;
else if(L<=l2) g[i][j]=c2;
else if(L<=l3) g[i][j]=c3;
else if(L<=l4) g[i][j]=c4;
else g[i][j]=inf;
}
floyd();
printf("Case %d:\n",k++);
while(m--){
scanf("%d%d",&a,&b);
if(g[a-][b-]==inf) printf("Station %d and station %d are not attainable.\n",a,b);
else printf("The minimum cost between station %d and station %d is %I64d.\n",a,b,g[a-][b-]);
}
}
return ;
}

hdu 1690 Bus System (最短路径)的更多相关文章

  1. hdu 1690 Bus System(Dijkstra最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1690 Bus System Time Limit: 2000/1000 MS (Java/Others ...

  2. hdu 1690 Bus System (有点恶心)

    Problem Description Because of the huge population of China, public transportation is very important ...

  3. HDU 1690 Bus System

    题目大意:给出若干巴士不同价格的票的乘坐距离范围,现在有N个站点,有M次询问,查询任意两个站点的最小花费 解析:由于是多次查询不同站点的最小花费,所以用弗洛伊德求解 时间复杂度(O^3) 比较基础的弗 ...

  4. HDU ACM 1690 Bus System (SPFA)

    Bus System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. hdu1690 Bus System(最短路 Dijkstra)

    Problem Description Because of the huge population of China, public transportation is very important ...

  6. hdu1690 Bus System (dijkstra)

    Problem Description Because of the huge population of China, public transportation is very important ...

  7. hdu 1690(Floyed)

    Bus System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. hdu 2377 Bus Pass

    Bus Pass Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. hdu 5552 Bus Routes

    hdu 5552 Bus Routes 考虑有环的图不方便,可以考虑无环连通图的数量,然后用连通图的数量减去就好了. 无环连通图的个数就是树的个数,又 prufer 序我们知道是 $ n^{n-2} ...

随机推荐

  1. mysql 题目练习

    1 新建一个测试数据库: create database test1 charset utf8; 2 进入数据库 use test1; 3 新建一个sql 文件 ,将下面内容复制进sql 文件 /* ...

  2. redhat防火墙管理

    systemctl status firewalldsystemctl stop firewalldsystemctl start firewalldsystemctl enable firewall ...

  3. libevent学习八(evbuffer)

    1.evbuffer以队列的形式管理字节,从尾部添加,从头部取出(FIFO) 2.evbuffer内部存储形式是多个独立的连续内存       接口 //创建和删除 struct evbuffer * ...

  4. VS Help Viewer 显示内容为HTML源码的问题

    万恶的IE10 为了学习,安装了一套Windows Server 2012+SQL 2012+VS 2012的环境,整体感觉还不错,只是在使用Help Viewer查看帮助的时候,发现显示内容居然为H ...

  5. focus如何实现事件委托

    事件委托是利用事件冒泡机制的一种优化手段,如果有很多列表元素要绑定事件,那么就可以用事件委托来优化(不需要给每个元素都绑定事件).但是对于focus这种特殊的表单事件,它不会冒泡,那么又该如何实现这一 ...

  6. C++11 TypeList 妙用

    源码展示: #include <iostream> using namespace std; template <typename ... Args> struct typel ...

  7. CSP201412-2:Z字形扫描

    引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...

  8. 对Java对象的认识与理解

    今天是我学习编程以来第一次写博客,记下平日学习所得,本来这几日都在学习web框架 但觉得梳理一下之前所学很有必要.毕竟之前学习Java感觉很粗略只是以考试为目的.所以就以<Thinking in ...

  9. 简单的图片滑动效果插件 jQuery.iocnSlider.js

    近几日在制作一个客户引导页面,其中有一个图片展示而且带滑动的效果.好久没练手了,索性自己写一个插件吧. 依据设计原型,需要满足两套分辨率下图片不同的尺寸,所以在css中使用了media query的相 ...

  10. Vuejs 实现简易 todoList 功能 与 组件

    todoList 结合之前 Vuejs 基础与语法 使用 v-model 双向绑定 input 输入内容与数据 data 使用 @click 和 methods 关联事件 使用 v-for 进行数据循 ...