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} ...
随机推荐
- Centos7安装PHP7
安装依赖 yum updateyum install gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel lib ...
- git --help出来的命令 + eclipse里用git小记
用法:git [--version] [--help] [-C <path>] [-c name=value] [--exec-path[=<path>]] ...
- [LeetCode] Remove Invalid Parentheses 移除非法括号
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all ...
- [LeetCode] Ugly Number II 丑陋数之二
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- 利用HttpWebRequest实现实体对象的上传
一 简介 HttpWebRequest和HttpWebResponse类是用于发送和接收HTTP数据的最好选择.它们支持一系列有用的属性.这两个类位 于System.Net命名空间,默认情况下这个类对 ...
- Apache问题处理服务器访问不了
1. 查看apache的错误日志 我的apache日志文件目录 /var/log/httpd/error.log [Sun Nov 20 21:17:24 2016] [error] server r ...
- linux-crontab定时任务
crontab命令常见于Unix和Linux的操作系统之中,用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于"crontab"文件中,以供之后读取和执行.通常 ...
- 兄弟连javascript学习笔记
/* Javascript:用来在页面中编写特效,和HTML.CSS一样都是有浏览器解析 Javascript语言: 一.JS如何运行(javascript,jscript,vbscript,appl ...
- Android基础总结(六)
创建第二个Activity(掌握) 需要在清单文件中为其配置一个activity标签 标签中如果带有这个子节点,则会在系统中多创建一个快捷图标 <intent-filter> <ac ...