HDU 1690 Bus System
题目大意:给出若干巴士不同价格的票的乘坐距离范围,现在有N个站点,有M次询问,查询任意两个站点的最小花费
解析:由于是多次查询不同站点的最小花费,所以用弗洛伊德求解 时间复杂度(O^3) 比较基础的弗洛伊德
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 1000000000000 typedef __int64 LL;
const int N = ; __int64 dis[N][N],place[N];
__int64 L1,L2,L3,L4,C1,C2,C3,C4;
int n,m; LL judge(LL x)
{
if(x < )
x *= -;
if(x > && x <= L1)
return C1;
else if(x > L1 && x <= L2)
return C2;
else if(x > L2 && x <= L3)
return C3;
else if(x > L3 && x <= L4)
return C4;
else
return INF;
} void floyd()
{
for(int k=; k<=n; k++)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(dis[i][j] > dis[i][k] + dis[k][j] && dis[i][k] != INF && dis[k][j] != INF)
dis[i][j] = dis[i][k] + dis[k][j];
}
}
}
} int main()
{
//freopen("input.txt","r",stdin);
int t;
int kase = ;
cin>>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",&place[i]);
}
for(int i=; i<=n; i++)
{
for(int j=i+; j<=n; j++)
{
__int64 x = place[i] - place[j];
dis[i][j] = dis[j][i] = judge(x);
}
}
floyd();
printf("Case %d:\n",kase++);
for(int i=; i<=m; i++)
{
int st,ed;
scanf("%d%d",&st,&ed);
if(dis[st][ed] != INF)
printf("The minimum cost between station %d and station %d is %I64d.\n",st,ed,dis[st][ed]);
else
printf("Station %d and station %d are not attainable.\n",st,ed);
}
}
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 (最短路径)
Bus System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 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} ...
随机推荐
- Centos 7 minimal install 无网络无ifconfig的解决
Centos7这个比较不厚道, minimal install下居然不带net-tools 先要连上网络 修改/etc/sysconfig/network-scripts/ifcfg-ens12312 ...
- 解决ASP.NET上传文件大小限制
第一种方法,主要适用于IIS6.0版本 一.修改配置Web.Config文件中的httpRuntime节点对于asp.net,默认只允许上传4M文件,增加如下配置,一般可以自定义最大文件大小.一.修改 ...
- linux内存管理
一.Linux 进程在内存中的数据结构 一个可执行程序在存储(没有调入内存)时分为代码段,数据段,未初始化数据段三部分: 1) 代码段:存放CPU执行的机器指令.通常代码区是共享的,即其它执行程 ...
- 新建structs2 web应用及structs.xml常用基础配置
建立一个structs2 web应用程序 1. 创建一个基本的web应用程序 2. 添加structs2的jar文件到Class Path 将structs2的最小jar包拷到WEB-INF/lib目 ...
- 做中学(Learning by Doing)之背单词-扇贝网推荐
做中学(Learning by Doing)之背单词-扇贝网推荐 看完杨贵福老师(博客,知乎专栏,豆瓣)的「继续背单词,8个月过去了」,我就有写这篇文章的冲动了,杨老师说: 有时候我会感觉非常后悔,如 ...
- java sound初探
网上关于java sound的正规资源讲解的非常好,本文不再给出示例,主要提供一些好的资源,并说说我的一些理解,用于形成对java sound的整体认识. 一.几个词汇 TTS:text-to-spe ...
- 【MySQL】mysql 1449 : The user specified as a definer ('root'@'%') does not exist
权限问题,授权 给 root 所有sql 权限 1.mysql> grant all privileges on *.* to root@"%" identified by ...
- C#笔记
关键字: 1.internal 被 internal 修饰的东西只能在本程序集(当前项目)内被使用. 注意事项: 1.解决c#代码引用c/c++代码出现的unsafe code错误警告提示 Unsaf ...
- vue.js之过渡效果-css
概述 vuejs的过渡效果可以让我们的页面元素在出现和消失时实现过渡.官方文档这样描述过渡效果的方式: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Anima ...
- 关于PHP扩展开发(收藏)
一.Linux shell命令: ls –lh 查看文件大小 du –a 查看文件及文件夹大小 -------------------------- nginx ------------- ...