题目大意:给出若干巴士不同价格的票的乘坐距离范围,现在有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的更多相关文章

  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 (最短路径)

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

  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. [LeetCode] Maximal Square 最大正方形

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...

  2. 高品质开源工具Chloe.ORM:支持存储过程与Oracle

    扯淡 这是一款高质量的.NET C#数据库访问框架(ORM).查询接口借鉴 Linq.借助 lambda 表达式,可以完全用面向对象的方式就能轻松执行多表连接查询.分组查询.聚合查询.插入数据.批量删 ...

  3. 【C#】透屏幕,屏幕扩展

    if (!SCREEN_STATE) { ) { System.Windows.Forms.Screen s2 = System.Windows.Forms.Screen.AllScreens[]; ...

  4. Android 提醒公共方法 Notification

    SimpAndroidFarme是近期脑子突然发热想做的android快速开发的框架,目标是模块化 常用的控件,方便新手学习和使用.也欢迎老鸟来一起充实项目:项目地址 今天的目标是做一个公共的提醒方法 ...

  5. Freemarker中空值 null的处理++++定义数组

    http://blog.java-zone.org/archives/800.html <#list listBlogPost as blogPost> </#list> 如果 ...

  6. JAVA与数据库MySQL相连接

    JDBC(Java数据库连接体系结构): 是Java实现数据库访问的应用程序编程接口,主要功能是管理存放在数据库中的数据.通过接口对象,应用程序可以完成与数据库的连接,执行SQL语句,从数据库中获取结 ...

  7. 定制sqlmap tamper脚本

    前言 渗透测试过程中遇到注入点常常丢到sqlmap中进行测试,假如网站有waf,sqlmap便无法直接注入了. 测试 在测试某个项目的过程中,一个页面的aid参数,习惯性的提交 and 1=1发现直接 ...

  8. 偷懒小工具 - Excel导出公共类

    说明 最近接了一个任务,就是做一个列表的Excel导出功能.并且有很多页面都会使用这个功能. 导出的Excel大体格式如图 很简单的列表,标题加背景色,然后不同类型,显示方式不一样.对齐方式不一样.不 ...

  9. UVA232

    这只是大概的雏形. 步骤就是:1输入网格,2给网格里的起始格编序号,3输出所有字母,前面要加序号 #include<stdio.h> #include<ctype.h> #in ...

  10. angular2学习--根模块

    最近有时间,学习一下angular2,根据自己的理解添加一些自己的理解,有什么不对的地方请指教, 学习的地址是https://angular.cn/ 下边是分享一下我学习过程 angular2和ang ...