题意:有一个公交系统的收费标准例如以下表:

然后问:给出 这些L1~4 & C1~4的值,然后 N个站。列出每一个站的X坐标。然后询问M次,问两个站台的最小花费
题解:那么这里非常明显是最短路问题。有一点的麻烦就在于建图,那么我们能够对于全部的点,用两个for循环。算出两两之间的距离。就能够得到花费是多少,同一时候建边。然后对于每次询问的点,我们就spfa一次就OK
<span style="font-size:14px;">#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring> using namespace std; #define INF 0xffffffffffffff
#define MAX 105
#define LL __int64 int N,M;
LL L1,L2,L3,L4,C1,C2,C3,C4;
LL X[MAX]; struct Edge{
int to,next;
LL cost;
}edge[MAX*MAX];
int head[MAX],tol; void add(int u,int v,LL cost)
{
edge[tol].to = v;
edge[tol].cost = cost;
edge[tol].next = head[u];
head[u] = tol++;
} void del() //处理建边
{
LL cost,dis;
for(int i = 1; i <= N; i ++){
for(int j = i+1; j <= N; j ++){
if(X[i] > X[j]) dis = X[i]-X[j];
else dis = X[j]-X[i]; if(dis > L4) cost = INF;
else if(dis > L3) cost = C4;
else if(dis > L2) cost = C3;
else if(dis > L1) cost = C2;
else cost = C1; add(i,j,cost);
add(j,i,cost);
}
}
} LL dis[MAX];
bool flag[MAX];
LL spfa(int src,int D)
{
for(int i = 1; i <= N; i ++) dis[i] = INF;
memset(flag,false,sizeof(flag));
dis[src] = 0;
flag[src] = true; queue<int>q;
q.push(src); while(!q.empty())
{
int u = q.front(); q.pop();
flag[u] = false;
for(int i = head[u]; i != -1; i = edge[i].next)
{
int v = edge[i].to; LL cost = edge[i].cost;
if(cost + dis[u] < dis[v])
{
dis[v] = cost+dis[u];
if(!flag[v])
{
q.push(v);
flag[v] = true;
}
}
}
}
return dis[D];
} int main()
{
int T;
scanf("%d",&T); for(int cas = 1; cas <= T; cas ++)
{
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 = 1; i <= N; i ++) scanf("%I64d",&X[i]); memset(head,-1,sizeof(head));
tol = 0; del(); printf("Case %d:\n",cas);
int a,b;
LL ans = 0;
for(int i = 0; i < M; i ++)
{
scanf("%d%d",&a,&b);
ans = spfa(a,b);
if(ans >= INF)
printf("Station %d and station %d are not attainable.\n",a,b);
else
printf("The minimum cost between station %d and station %d is %I64d.\n",a,b,ans);
}
} return 0;
}</span>

那么这里的话,还要注意的是 由于坐标值比較大,我们用 64位来保存

hdu1690Bus System--解题报告的更多相关文章

  1. 【LeetCode】1166. Design File System 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 目录树 日期 题目地址https://leetc ...

  2. 【LeetCode】609. Find Duplicate File in System 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  3. Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告

    Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...

  4. 北邮新生排位赛1解题报告d-e

    话说cdsn要是前面插入源代码又什么都不放就会出现奇怪的源代码?不知道是哪个网页的 407. BLOCKS 时间限制 1000 ms 内存限制 65536 KB 题目描述 给定一个N∗M的矩阵,求问里 ...

  5. C-C Radar Installation 解题报告

    C-C    Radar Installation   解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#pr ...

  6. ZOJ_3950_How Many Nines 解题报告及如何对程序进行测试修改

    The 17th Zhejiang University Programming Contest Sponsored by TuSimple Solution: #include <stdio. ...

  7. LeetCode: Permutations 解题报告

    Permutations Given a collection of numbers, return all possible permutations. For example,[1,2,3] ha ...

  8. ACM-ICPC 2017 Asia HongKong 解题报告

    ACM-ICPC 2017 Asia HongKong 解题报告 任意门:https://nanti.jisuanke.com/?kw=ACM-ICPC%202017%20Asia%20HongKon ...

  9. poj分类解题报告索引

    图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...

  10. 【九度OJ】题目1040:Prime Number 解题报告

    [九度OJ]题目1040:Prime Number 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1040 题目描述: Ou ...

随机推荐

  1. 一个对 Dijkstra 的采访视频

    之前在微博上推荐了一个对 Dijkstra 的采访视频,看了两遍之后觉得实在很好,所以再正式推荐一下.大部分人可能都知道他对图论算法和操作系统的贡献,而其实 Dijkstra 在程序语言上的造诣也很深 ...

  2. 26个Jquery1.4使用小技巧

    1. 禁止右键点击 1.       $(document).ready(function(){ 2.           $(document).bind("contextmenu&quo ...

  3. CentOS 5.5 虚拟机安装 VirtualBox 客户端增强功能

    .启动安装在 VirtualBox 中的 CentOS 5.5 虚拟机,点击“设备” => “安装增强功能”.这个时候你就可以看到有一个“光盘”已经挂载到 CentOS 5.5 的桌面上了.它包 ...

  4. 迭代最近点算法 Iterative Closest Points

    研究生课程系列文章参见索引<在信科的那些课> 基本原理 假定已给两个数据集P.Q, ,给出两个点集的空间变换f使他们能进行空间匹配.这里的问题是,f为一未知函数,而且两点集中的点数不一定相 ...

  5. OpenStreetMap地图数据介绍(转)

    原文链接:每日一读 Packtpub.OpenStreetMap(1) 相信绝大多数人都知道Wiki,但要提起地图,大家第一反应肯定是Google地图.在没看这本书之前,还真不知原来还有OpenStr ...

  6. HttpMessageConverter

    HttpMessageConverter<T>是Spring3的一个重要接口,它负责将请求信息转换为一个对象(类型为T),将对象(类型为T)输出为响应信息. DispatcherServl ...

  7. TreeMap源代码深入剖析

    第1部分 TreeMap介绍 A Red-Black tree based NavigableMap implementation. The map is sorted according to th ...

  8. DB-library 常用函数

    以下转自:http://blog.csdn.net/lwbeyond/article/details/5620801 1. Dbcmd和dbfcmd 函数原形: Dbcmd(DBPROCESS *pr ...

  9. Merge Sorted Array leetcode java(回顾MergeTwoArray和MergeTwoLinkedList)

    题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assum ...

  10. JavaScript事件代理和事件委托

    一.概述: 那什么叫事件委托呢?它还有一个名字叫事件代理,JavaScript高级程序设计上讲:事件委托就是利用事件冒泡,只指定一个事件处理程序,就可以管理某一类型的所有事件.那这是什么意思呢?网上的 ...