Bus System

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5709    Accepted Submission(s): 1449

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.
 
 
核心算法: 顶点队的最短路径,直接用floyd暴力算法;PS:注意要用__int64;
 
AC代码:
 #include<stdio.h>
#include<string.h>
#include<math.h>
__int64 g[][];
__int64 L1,L2,L3,L4;
__int64 c1,c2,c3,c4;
void floyd(__int64 n)
{
for(__int64 k=;k<=n;k++)
{
for(__int64 i=;i<=n;i++)
{
for(__int64 j=;j<=n;j++)
{
if(g[i][k]+g[k][j]<g[i][j])
{
g[i][j]=g[i][k]+g[k][j];
}
}
}
}
}
__int64 func(__int64 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 ;
}
int main()
{
__int64 Q,t,i,j;
scanf("%I64d",&Q);
__int64 poi[];
for(t=;t<=Q;t++)
{
memset(poi,,sizeof(poi));
scanf("%I64d %I64d %I64d %I64d",&L1,&L2,&L3,&L4);
scanf("%I64d %I64d %I64d %I64d",&c1,&c2,&c3,&c4);
__int64 n,m,x;
scanf("%I64d %I64d",&n,&m);
for(i=;i<=n;i++)
scanf("%I64d",&poi[i]);
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
__int64 len=(poi[j]-poi[i]);
if(len<)
len=-*len;
g[j][i]=g[i][j]=func(len);
}
}
floyd(n); printf("Case %I64d:\n",t);
for(i=;i<=m;i++)
{
__int64 a,b;
scanf("%I64d %I64d",&a,&b);
if(g[a][b]==)
printf("Station %I64d and station %I64d are not attainable.\n",a,b);
else
printf("The minimum cost between station %I64d and station %I64d is %I64d.\n",a,b,g[a][b]);
}
}
return ;
}

HDOJ 1690的更多相关文章

  1. 杭电hdoj题目分类

    HDOJ 题目分类 //分类不是绝对的 //"*" 表示好题,需要多次回味 //"?"表示结论是正确的,但还停留在模块阶 段,需要理解,证明. //简单题看到就 ...

  2. HDOJ 题目分类

    HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:   ...

  3. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  5. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  7. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  8. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  9. 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ

    前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...

随机推荐

  1. 百度地图 api 功能封装类 (ZMap.js) 本地搜索,范围查找实例 [源码下载]

    相关说明 1. 界面查看: 吐槽贴:百度地图 api 封装 的实用功能 [源码下载] 2. 功能说明: 百度地图整合功能分享修正版[ZMap.js] 实例源码! ZMap.js 本类方法功能大多使用 ...

  2. (转载)Go语言开发环境配置

    一.我为什么要学习go语言 当今已经是移动和云计算时代,Go出现在了工业向云计算转型的时刻,简单.高效.内 置并发原语和现代的标准库让Go语言尤其适合云端软件开发(毕竟它就是为此而设计的).到2014 ...

  3. Ajax实现联动效果

    用到了地区的数据库 html代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="s ...

  4. 【前端学习】git命令行界面

    学习目标:掌握git命令行界面的操作.掌握最基本的clone add commit push pull操作. 先下载客户端:http://github-windows.s3.amazonaws.com ...

  5. 【bzoj3246】 Ioi2013—Dreaming

    www.lydsy.com/JudgeOnline/problem.php?id=3246 (题目链接) 题意 给出一棵不完全的树,要求在树上连最少的边使得所有点联通,并且使得两点间最大距离最小. S ...

  6. 【poj2546】 Circular Area

    http://poj.org/problem?id=2546 (题目链接) 题意 求两圆的面积交 Solution 一道水题Wa死我了,肯定是昨晚搞太晚的缘故= =. 两圆的位置关系有5种,而这里要求 ...

  7. 【poj1962】 Corporative Network

    http://poj.org/problem?id=1962 (题目链接) 时隔多年又一次写带权并查集. 题意 n个节点,若干次询问,I x y表示从x连一条边到y,权值为|x-y|%1000:E x ...

  8. PowerDesigner15下载、安装以及破解

    一.先安装PowerDesigner15(PowerDesigner15.1.0.2850),下载地址:点击下载 二.破解文件下载地址: 找到一个,居然这家伙的东西不是免费的:点击跳转 三.破解方法: ...

  9. NOIP2008普及组题解

    NOIP2008普及组题解 从我在其他站的博客直接搬过来的 posted @ 2016-04-16 01:11 然后我又搬回博客园了233333 posted @ 2016-06-05 19:19 T ...

  10. 常用数据库 JDBC URL 格式

    一 常用数据库 JDBC URL 格式 1 sqLite  驱动程序包名:sqlitejdbc-v056.jar 驱动程序类名: org.sqlite.JDBC JDBC URL: jdbc:sqli ...