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.
 
 
题目大意:乘公交车的价格随公交站距离的远近有不同的标准,就是按照每个测试数据第一行的数字,接着是有n个站点有m个提问,接着n行,假设有个原点,所有站点在一条直线上,n行每个数字表示第i个站点距离原点的距离,m个提问,表示出发点和终点;
 
 
直接用Dijkastra就ok了 稍稍做一点点的变形,要注意的本题数据比较大 在定义最大值常量的时候要注意 一开始还WA了好多遍 结果定义成
const __int64 inf=0xffffffffffffff;
就过了,输入输出也要用__int64 !
 #include <iostream>
#include <cstdio>
using namespace std;
const __int64 inf=0xffffffffffffff;
__int64 dist[],node[],vis[];
__int64 l[],c[],n; __int64 ab(__int64 a)
{
return a>?a:-a;
}
__int64 cost(__int64 dis)
{
if (dis>=&&dis<=l[]) return c[];
if (dis>l[]&&dis<=l[]) return c[];
if (dis>l[]&&dis<=l[]) return c[];
if (dis>l[]&&dis<=l[]) return c[];
} void Dijkstra(__int64 start,__int64 end)
{
for(int i=; i<=n; i++)
node[i]=inf,vis[i]=;
__int64 tm=start;
node[tm]=;
vis[tm]=;
for(int k=; k<=n; k++)
{
__int64 Min=inf;
for (int i=; i<=n; i++)
if(!vis[i]&&Min>node[i])
{
Min=node[i];
tm=i;
//cout<<" "<<tm<<" "<<Min<<endl;
}
if(tm==end)
{
printf("The minimum cost between station %I64d and station %I64d is %I64d.\n",start,end,node[end]);
return ;
}
vis[tm]=;
for(int i=; i<=n; i++)
if(ab(dist[i]-dist[tm])<=l[]&&!vis[i]&&node[i]>node[tm]+cost(ab(dist[i]-dist[tm])))
{
//cout<<" "<<i<<" "<<node[tm]<<" "<<ab(dist[i]-dist[tm])<<" "<<hash[ab(dist[i]-dist[tm])]<<endl;
node[i]=node[tm]+cost(ab(dist[i]-dist[tm]));
}
}
printf ("Station %I64d and station %I64d are not attainable.\n",start,end);
} int main ()
{
int t,k=;
cin>>t;
while (t--)
{
//int l1,l2,l3,c1,c2,c3,c4;
cin>>l[]>>l[]>>l[]>>l[]>>c[]>>c[]>>c[]>>c[];
int m;
cin>>n>>m;
for(int i=; i<=n; i++)
cin>>dist[i];
printf ("Case %d:\n",k++);
while (m--)
{
int a,b;
cin>>a>>b;
Dijkstra(a,b);
}
}
}


 

hdu1690 Bus System(最短路 Dijkstra)的更多相关文章

  1. hdu1690 Bus System (dijkstra)

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

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

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

  3. hdu 2544 最短路 Dijkstra

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544 题目分析:比较简单的最短路算法应用.题目告知起点与终点的位置,以及各路口之间路径到达所需的时间, ...

  4. 算法学习笔记(三) 最短路 Dijkstra 和 Floyd 算法

    图论中一个经典问题就是求最短路.最为基础和最为经典的算法莫过于 Dijkstra 和 Floyd 算法,一个是贪心算法,一个是动态规划.这也是算法中的两大经典代表.用一个简单图在纸上一步一步演算,也是 ...

  5. HDU ACM 1690 Bus System (SPFA)

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

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

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

  7. 单源最短路dijkstra算法&&优化史

    一下午都在学最短路dijkstra算法,总算是优化到了我能达到的水平的最快水准,然后列举一下我的优化历史,顺便总结总结 最朴素算法: 邻接矩阵存边+贪心||dp思想,几乎纯暴力,luoguTLE+ML ...

  8. hdu 1690 Bus System (最短路径)

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

  9. HUD.2544 最短路 (Dijkstra)

    HUD.2544 最短路 (Dijkstra) 题意分析 1表示起点,n表示起点(或者颠倒过来也可以) 建立无向图 从n或者1跑dij即可. 代码总览 #include <bits/stdc++ ...

随机推荐

  1. 字符串(后缀数组||SAM):NOI2015 品酒大会

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAByIAAALuCAIAAABtq0bwAAAgAElEQVR4nOy9f2wb150vev4boESeln ...

  2. 数据结构(Splay平衡树):HAOI2008 排名系统

    [HAOI2008] 排名系统 [题目描述] 排名系统通常要应付三种请求:上传一条新的得分记录.查询某个玩家的当前排名以及返回某个区段内的排名记录.当某个玩家上传自己最新的得分记录时,他原有的得分记录 ...

  3. Listview加载更多是,恢复到原来的位置,如果不加特殊处理,总是跳转第一条

    1.记录listView滚动到的位置的坐标,然后利用listView.scrollTo精确的进行恢复 listView.setOnScrollListener(new OnScrollListener ...

  4. GPRS

    互动百科http://www.baike.com/wiki/GPRS 百度百科http://baike.baidu.com/link?url=M-ElL_qR1bwzUr7BdrDgN4EzBhYYJ ...

  5. [经典] 最X(长 | 大和 | 大积)Y(子序列 | 子字符串)

    Note: 子序列,可以不连续:子字符串,必须连续. 以下题目按在我看看来的难度从易到难排列: 最大和子序列(Maximum sum subsequence) 这道题纯属娱乐...应该不会有人出这种题 ...

  6. IOS面试题(虽然我们很少用)

    其实我们会考很多C的基本知识,主要还是交流,这个题就是防止那些小白. 1.Objective-C中,与alloc语义相反的方法是dealloc还是release?与retain语义相反的方法是deal ...

  7. [转]windows10 64位环境下安装mysql5.7.17

    今天以zip模式在windows10 64位环境下安装mysql5.7,到最后一步提示mysql服务无法启动. 安装步骤如下: 1.配置环境变量 我的电脑->属性->高级->环境变量 ...

  8. Java Web应用的开发模式

    一.概述 从互联网诞生的第一天起,web从一个简单的静态页面,发展到今天五花八门.令人眼花缭乱的复杂应用,大到企业级的web应用系统,小到简单的SPA管理系统.在硬件性能提升的同时,通过各种技术实现了 ...

  9. bzoj2631: tree lct

    要打mul和add的lct 50000+的mod用unsigned int好了TAT (坑爹没打pc('\n');(静态)调了好久,样例竟然只输出一个,orz,也不提示PE T_T) #include ...

  10. Angular2学习

    1.新建项目 2.新建Model public class TodoItem { public int Id { get; set; } public string Key { get; set; } ...