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. angular_$attrs

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  2. C语言和数据结构的书单-再次推荐

    一.推荐专业书单: 1)         C语言方面: n  明解C语言——适合初学者 豆瓣链接:https://book.douban.com/subject/23779374/ 推荐理由:< ...

  3. Day One

    站立式会议 站立式会议内容总结 442 今天完成:学习Android 三种常用的adapter的使用方法,实现主页的可折叠列表 遇到问题:在实现自定义Adapter时,调用出现错误.已解决. 明天计划 ...

  4. 自定义EL

    1.建一个类 package com.zh.util; public class GetInFo { public static String eval(String infix){ //注意的是这里 ...

  5. CSS模版收集

    Css Reset by Eric MeyerURL:http://www.ahrefmagazine.com/web-design/30-useful-css-snippets-for-develo ...

  6. 表单脚本api_contenteditable

    <html> <head></head> <body> <form> <div contenteditable>ssadas&l ...

  7. hdu1828 线段树+离散化+扫描线

    添加lb[],rb[]数组,来标记竖边.添加num,来计算竖边的个数,因为计算周长的时候,未覆盖的竖边都要加. #include<stdio.h> #include<stdlib.h ...

  8. BZOJ-1951 古代猪文 (组合数取模Lucas+中国剩余定理+拓展欧几里得+快速幂)

    数论神题了吧算是 1951: [Sdoi2010]古代猪文 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1573 Solved: 650 [Submit ...

  9. COGS8 备用交换机

    备用交换机 ★★   输入文件:gd.in   输出文件:gd.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] n个城市之间有通讯网络,每个城市都有通讯交换机,直接或间 ...

  10. java连接mysql(三)

    事务的四大特性(ACID) 原子性(Atomicity) 原子性是指事务是一个不可分割的工作单位,事务中的操作要么全部成功,要么全部失败.比如在同一个事务中的SQL语句,要么全部执行成功,要么全部执行 ...