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

然后问:给出 这些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. Arcgis Runtime for andriod 100 加载geodatabase

    private void LoadMY(){ try { String mainGeodatabaseFilePath = YLPub.getMapData() + "/gismap/sl. ...

  2. 【maven】排除maven中jar包依赖的解决过程 例子:spring cloud启动zipkin,报错maven依赖jar包冲突 Class path contains multiple SLF4J bindings.

    一直对于maven中解决jar包依赖问题的解决方法纠结不清: 下面这个例子可以说明一个很简单的解决方法: 项目启动报错: Connected to the target VM, address: '1 ...

  3. 使用POI操作Excel时对事先写入模板的公式强制执行

    场景:POI读取Excel模板. 当使用POI操作Excel时,发现由POI生成的公式能够在打开Excel是被执行, 而事先手工写入Excel模板文件的公式则不自动被调用,必须手动双击该Cell才能生 ...

  4. Android之zip包换肤(极力推荐)

    转自:http://www.eoeandroid.com/thread-102536-1-1.html 直接上图,以图为证,哈哈 第一图为原始的皮肤:<ignore_js_op> 第二种为 ...

  5. python植入后门backdoor程序的方法?

    后门程序 from gevent.backdoor import BackdoorServer server = BackdoorServer((), banner="Hello from ...

  6. waf bypass

    1.前言 去年到现在就一直有人希望我出一篇关于waf绕过的文章,我觉得这种老生常谈的话题也没什么可写的.很多人一遇到waf就发懵,不知如何是好,能搜到的各种姿势也是然并卵.但是积累姿势的过程也是迭代的 ...

  7. 如果不用jQuery,Ajax你还能写出多少?

    许久之前发过一篇关于Ajax的博客,通篇讲的都是通过jQuery编写Ajax,可能因为jQuery在这方面做的实在太好,以至于突然发现不用jQuery的话自己都模糊了Ajax的写法,这里重温一下. F ...

  8. Win10 Docker 安装使用

    1.前言 Docker最近推出了可以运行在Win10和Mac上的稳定版本,让我们赶紧来体验一下. 2.安装准备 需要的条件为: 64bit Windows 10,开启Hyper-V 2.1 下载Doc ...

  9. 【Python】Django删除数据迁移记录

    find . -path "*migrations*" -name "*.py" -not -path "*__init__*" -exec ...

  10. (转)深入浅出K-Means算法

    原文地址:http://www.csdn.net/article/2012-07-03/2807073-k-means 摘要:在数据挖掘中,K-Means算法是一种 cluster analysis ...