hdu 1690 Bus System (最短路径)
Bus System
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6082 Accepted Submission(s): 1560
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.
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.
2
3
4
2
3
10
简单最短路径,注意是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 (最短路径)的更多相关文章
- hdu 1690 Bus System(Dijkstra最短路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1690 Bus System Time Limit: 2000/1000 MS (Java/Others ...
- hdu 1690 Bus System (有点恶心)
Problem Description Because of the huge population of China, public transportation is very important ...
- HDU 1690 Bus System
题目大意:给出若干巴士不同价格的票的乘坐距离范围,现在有N个站点,有M次询问,查询任意两个站点的最小花费 解析:由于是多次查询不同站点的最小花费,所以用弗洛伊德求解 时间复杂度(O^3) 比较基础的弗 ...
- HDU ACM 1690 Bus System (SPFA)
Bus System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu1690 Bus System(最短路 Dijkstra)
Problem Description Because of the huge population of China, public transportation is very important ...
- hdu1690 Bus System (dijkstra)
Problem Description Because of the huge population of China, public transportation is very important ...
- hdu 1690(Floyed)
Bus System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 2377 Bus Pass
Bus Pass Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 5552 Bus Routes
hdu 5552 Bus Routes 考虑有环的图不方便,可以考虑无环连通图的数量,然后用连通图的数量减去就好了. 无环连通图的个数就是树的个数,又 prufer 序我们知道是 $ n^{n-2} ...
随机推荐
- WeTest功能优化第2期:云真机智能投屏,调试告别鼠标
第2期功能优化目录 [云真机视频映射]云真机画面本地映射[兼容性测试报告]新增问题机型聚类功能[新增Android9.0]同步上线最新安卓系统 本期介绍的云测产品功能优化,既有重磅级技术突破,也有报告 ...
- 多台服务器下同步文件夹数据(rsync+inotify)
网上有很多讲解rsync+inotify的教程,我就先贴出一个来大家去看吧,基本都是类似的. http://www.jb51.net/article/57011.htm 我就强调几点,按照上面的方法配 ...
- Python对象引用问题总结
对于对象引用问题,一直是一知半解的状态,现整理以备使用. 操作不可变对象进行加减运算时,会在内存中创建新的不可变实例,不会影响原来的引用>>> c=12>>> d= ...
- 安装mysql-5.7.12-winx64
之前安装mysql时未做总结,换新电脑,补上安装记录,安装的时候,找了些网友的安装记录,发现好多坑 1.mysql-5.7.12-winx64.zip下载 官方下载地址:http://dev.mysq ...
- 看图写树 (Undraw the Trees UVA - 10562)
题目描述: 原题:https://vjudge.net/problem/UVA-10562 题目思路: 递归找结点 //自己的代码测试过了,一直WA,贴上紫书的代码 AC代码 #include< ...
- Java学习 · 初识 容器和数据结构
容器和数据结构 1. 集合的引入 a) 集合的使用场景:需要将一些相同结构的个体整合到一起时 i. 新闻列表 ii. 邮件列表 iii. ...
- org.apache.spark.launcher.Main源码分析
public static void main(String[] argsArray) throws Exception { //org.apache.spark.launcher.Main chec ...
- 如何借助windows的VHD引导特性实现VHD多windows系统共存
近期,由于一些需要,需要运行3个windows系统,具体需要如何此处略去,现将实现方式共享如下. 测试环境: HP 820 G2, 4G内存, 500G SSD硬盘 windows 7 企业版 win ...
- leetcode个人题解——#19 Remove Nth Node From End of List
思路:设置两个指针,其中第二个指针比第一个延迟n个元素,这样,当第二个指针遍历到指针尾部时,对第一个指针进行删除操作. 当然,这题要注意一些边界值,比如输入[1,2] n=2时如果按照思路走会指向未分 ...
- usdt信息小结
https://blog.csdn.net/weixin_42208011/article/details/80499536 https://blog.csdn.net/weixin_42208011 ...