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. 第四十二课:基于CSS的动画引擎

    由于低版本浏览器不支持css3 animation,因此我们需要根据浏览器来选择不同的动画引擎.如果浏览器支持css3 animation,那么就使用此动画引擎,如果不支持,就使用javascript ...

  2. SQL的主键和外键

    SQL的主键和外键的作用: 外键取值规则:空值或参照的主键值. (1)插入非空值时,如果主键表中没有这个值,则不能插入. (2)更新时,不能改为主键表中没有的值. (3)删除主键表记录时,你可以在建外 ...

  3. 手工部署项目到tomcat

    正确的方法是,在eclipse里面的项目伤右键,然后Export,然后在弹出的框当中选择导出类型,这里选择web下面的WAR file,然后下一步,选择导出到哪里,然后把导出的war文件放到tomca ...

  4. 在Windows和UNIX下利用PHP和LDAP进行身份验证

    我现在的老板曾要求我为企业内部的Web服务提供一种标准的身份验证方法.我遇到的一个主要问题就是我们公司主要使用了两种平台:UNIX和.所以,我的第一个想法并不很成功:它要求每个员工都使用UNIX或者L ...

  5. HTML5的拖拽时间 ondragstart

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. BIEE 配置邮箱服务器

    找个免费邮件服务器126或者163的 登录em地址,点击“部署”——>“邮件”——>“锁定并编辑”——>应用——>激活更改——>重新启动以应用最近更改——>重新启动 ...

  7. BZOJ-1975 魔法猪学院 K短路 (A*+SPFA)

    1975: [Sdoi2010]魔法猪学院 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1323 Solved: 433 [Submit][Statu ...

  8. Mysql安全配置

    相关学习资料 http://drops.wooyun.org/tips/2245 http://www.cnblogs.com/siqi/archive/2012/11/21/2780966.html ...

  9. JDBC中prepareStatement 和Statement 的区别

    package util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedSta ...

  10. POJ 3273 Monthly Expense

    传送门 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John is an astounding accounting wiza ...