poj 1847 Tram【spfa最短路】】的更多相关文章

Tram 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/N Description Tram network in Zagreb consists of a number of intersections and rails connecting some of them. In every intersection there is a switch pointing to the one of the rails goi…
POJ 1847 Tram (最短路径) Description Tram network in Zagreb consists of a number of intersections and rails connecting some of them. In every intersection there is a switch pointing to the one of the rails going out of the intersection. When the tram ent…
POJ 1847 最短路 每个点都有初始指向,问从起点到终点最少要改变多少次点的指向 *初始指向的那条边长度为0,其他的长度为1,表示要改变一次指向,然后最短路 =========高亮!!!==========数组要开n^2的QAQ #include <iostream> #include <cstdio> #include <queue> using namespace std; #define SZ 10005//开n^2的数组!! #define INF 1e9+…
Tram Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12005   Accepted: 4365 Description Tram network in Zagreb consists of a number of intersections and rails connecting some of them. In every intersection there is a switch pointing to t…
题意很好懂,但是不好下手.这里可以把每个点编个号(1-25),看做一个点,然后能够到达即为其两个点的编号之间有边,形成一幅图,然后求最短路的问题.并且pre数组记录前驱节点,print_path()方法可用算法导论上的. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <ve…
Tram Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14630 Accepted: 5397 Description Tram network in Zagreb consists of a number of intersections and rails connecting some of them. In every intersection there is a switch pointing to the o…
http://poj.org/problem?id=1847 一个水题,用来熟悉熟悉spfa和floyd的. 题意:有m条的铁路,要从x,到y, 之后分别就是条铁路与其他铁路的交点.第一个输入的为有n个交点.之后第一个输入的点,当前铁路到这个点是不要转向的,也就是权值为0,其余的权值都为1,求从x到y的最短路,如果到不了输出-1 裸的floyd和spfa: #include <stdio.h> #include <string.h> #define inf 0x3f3f ][];…
http://poj.org/problem?id=1847 这道题题意不太容易理解,n个车站,起点a,终点b:问从起点到终点需要转换开关的最少次数 开始的那个点不需要转换开关 数据: 3 2 1//第一个数车站总数3,第二个数起点2,第三个数终点1 2 2 3//第一个数有2个点可到达,两个点分别是2(不需要转换开关),3(需要转换开关) 2 3 1 2 1 2可转化为最短路来写,转换开关次数当做最短路径 #include<stdio.h> #include<stdlib.h>…
Description Tram network in Zagreb consists of a number of intersections and rails connecting some of them. In every intersection there is a switch pointing to the one of the rails going out of the intersection. When the tram enters the intersection…
题意:给出n个站点,每个站点都有铁路通向其他站点 如果当前要走得路恰好是该站点的开关指向的铁路,则不用扳开关,否则要手动扳动开关,给出起点和终点,问最少需要扳动多少次开关 输入的第一行是n,start,end 接下来的n行,每一行中,第一个数是该站点向外连接的铁路条数, 第二个数是该站点的开关指向的铁路(因为这儿没有读懂= =所以都建不出图来--5555参见这一句话:Switch in the i-th intersection is initially pointing in the dire…