把每个电梯口看作一个节点, 然后计算边的权值的时候处理一下, 就ok了。

#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
using namespace std; const int MAXN = 112;
struct Edge { int v, id; };
struct node
{
int t, v, id;
bool operator < (const node& rhs) const
{
return t > rhs.t;
}
};
vector<Edge> g[MAXN];
vector<int> a;
int d[MAXN], speed[10], n, k, x; void solve()
{
priority_queue<node> q;
REP(i, 0, MAXN) d[i] = (i == 0 ? 0 : 1e9);
q.push(node{0, 0, -1}); while(!q.empty())
{
node x = q.top(); q.pop();
int u = x.v;
if(x.t != d[u]) continue; REP(i, 0, g[u].size())
{
int v = g[u][i].v, id = g[u][i].id;
int w = speed[id] * abs(u - v);
if(x.id != id && x.id != -1) w += 60; if(d[v] > d[u] + w)
{
d[v] = d[u] + w;
q.push(node{d[v], v, id});
}
}
} if(d[k] == 1e9) puts("IMPOSSIBLE");
else printf("%d\n", d[k]);
} int main()
{
while(~scanf("%d%d", &n, &k))
{
REP(i, 0, MAXN) g[i].clear();
REP(i, 0, n) scanf("%d", &speed[i]); REP(i, 0, n)
{
a.clear();
scanf("%d", &x);
a.push_back(x); while(getchar() != '\n')
{
scanf("%d", &x);
a.push_back(x);
} REP(r, 0, a.size())
REP(j, r + 1, a.size())
{
g[a[j]].push_back(Edge{a[r], i});
g[a[r]].push_back(Edge{a[j], i});
}
} solve();
} return 0;
}

紫书 习题 11-7 UVa 10801 (单源最短路变形)的更多相关文章

  1. UVa 12661 (单源最短路) Funny Car Racing

    题意: 有一个赛车跑道,可以看做一个加权有向图.每个跑道(有向边)还有一个特点就是,会周期性地打开a秒,然后关闭b秒.只有在赛车进入一直到出来,该跑道一直处于打开状态,赛车才能通过. 开始时所有跑道处 ...

  2. Aizu 2249Road Construction 单源最短路变形《挑战程序设计竞赛》模板题

    King Mercer is the king of ACM kingdom. There are one capital and some cities in his kingdom. Amazin ...

  3. 紫书 习题 11-2 UVa 1001 (Floyd)

    这道题只是在边上做一些文章. 这道题起点终点可以看成半径为0的洞, 我是直接加入了洞的数组. 边就是两点间的距离减去半径, 如果结果小于0的话, 距离就为0, 距离不能为负 然后我看到n只有100, ...

  4. 用scheme语言实现SPFA算法(单源最短路)

    最近自己陷入了很长时间的学习和思考之中,突然发现好久没有更新博文了,于是便想更新一篇. 这篇文章是我之前程序设计语言课作业中一段代码,用scheme语言实现单源最段路算法.当时的我,花了一整天时间,学 ...

  5. 最短路模板(Dijkstra & Dijkstra算法+堆优化 & bellman_ford & 单源最短路SPFA)

    关于几个的区别和联系:http://www.cnblogs.com/zswbky/p/5432353.html d.每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有S个(草儿家到 ...

  6. [ACM_图论] Domino Effect (POJ1135 Dijkstra算法 SSSP 单源最短路算法 中等 模板)

    Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...

  7. 单源最短路_SPFA_C++

    当我们需要求一个点到其它所有点的最短路时,我们可以采用SPFA算法 代码特别好写,而且可以有环,但是不能有负权环,时间复杂度是O(α(n)n),n为边数,α(n)为n的反阿克曼函数,一般小于等于4 模 ...

  8. 【UVA1416】(LA4080) Warfare And Logistics (单源最短路)

    题目: Sample Input4 6 10001 3 21 4 42 1 32 3 33 4 14 2 2Sample Output28 38 题意: 给出n个节点m条无向边的图,每条边权都为正.令 ...

  9. 【算法系列学习】Dijkstra单源最短路 [kuangbin带你飞]专题四 最短路练习 A - Til the Cows Come Home

    https://vjudge.net/contest/66569#problem/A http://blog.csdn.net/wangjian8006/article/details/7871889 ...

随机推荐

  1. php安装redis扩展 windows

    官方php_redis.dll 找了很久,感谢热心的网友,这是php官方的 php_redis.dll http://windows.php.net/downloads/pecl/releases/r ...

  2. Jquery_Validate 表单校验的使用

    一.效果图: 二.JqueryValidate的好处 在做注册.或者类似以上的表单提交的时候,大家是不是都很烦那种,把数据拿到后台去判断, 可能经过了正则表达式之类的复杂判断,然后发现数据错误.接着通 ...

  3. java中的接口中的方法

    题目如下:(多选题)请选择以下接口定义正确的方法() A:public static void main (String[] args); B:private void test(); C:publi ...

  4. 2015 Multi-University Training Contest 4 hdu 5338 ZZX and Permutations

    ZZX and Permutations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/O ...

  5. angular-Then的用法

    then怎么使用(主要是如何从中提取出我们需要的后台返回的数据):then(fn) 方法中带一个参数,这个参数就是要被执行的函数,并且,这个作为参数的函数本身有一个参数,这个参数就是我们需要的数据,这 ...

  6. BZOJ——1787: [Ahoi2008]Meet 紧急集合

    http://www.lydsy.com/JudgeOnline/problem.php?id=1787 题目描述 输入 输出 样例输入 6 4 1 2 2 3 2 4 4 5 5 6 4 5 6 6 ...

  7. HDU Train Problem I (STL_栈)

    Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...

  8. 【从零之六&amp;完结】android口语对话系统(RavenClaw java版 含所有源代码)

    ! !! 更新:最新源码放到了github上,认为还不错点个星啊! 点击打开链接 做了一个半月最终完毕了,以下这个就是我參考Olympus/RavenClaw系统编写的对话管理系统.眼下实现了一个简单 ...

  9. Android Parcelable vs Serializable

    序列化 在Android中.对象在实现序列化之前是无法直接作为Intent參数在Activity之间传递的. Android中对象序列化能够通过实现Serializable接口或者实现Parcelab ...

  10. js判断是对象还是集合

    /*============================================ 函数功能:对返回数据中的列表数据进行非空处理 ============================== ...