POJ 1847 Tram (最短路径)】的更多相关文章

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: 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 这道题题意不太容易理解,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>…
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…
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…
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…
题目传送门 题意:这题题目难懂.问题是A到B最少要转换几次城市.告诉每个城市相连的关系图,默认与第一个之间相连,就是不用转换,其余都要转换. 分析:把第一个城市权值设为0, 其余设为0.然后Floyd跑一下,得到A到B最少转换几次.有点水 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 1e2 + 5; const int INF =…
题意很好懂,但是不好下手.这里可以把每个点编个号(1-25),看做一个点,然后能够到达即为其两个点的编号之间有边,形成一幅图,然后求最短路的问题.并且pre数组记录前驱节点,print_path()方法可用算法导论上的. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <ve…
题意:给出n个站点,每个站点都有铁路通向其他站点 如果当前要走得路恰好是该站点的开关指向的铁路,则不用扳开关,否则要手动扳动开关,给出起点和终点,问最少需要扳动多少次开关 输入的第一行是n,start,end 接下来的n行,每一行中,第一个数是该站点向外连接的铁路条数, 第二个数是该站点的开关指向的铁路(因为这儿没有读懂= =所以都建不出图来--5555参见这一句话:Switch in the i-th intersection is initially pointing in the dire…
分析:d[i]表示到i点,最少的操作数 #include<cstdio> #include<cstring> #include<queue> #include<cstdlib> #include<algorithm> #include<vector> #include<cmath> using namespace std; typedef long long LL; +; const int INF=0x3f3f3f3f;…
题意:有向图有N个点,当电车进入交叉口(某点)时,它只能在开关指向的方向离开. 如果驾驶员想要采取其他方式,他/她必须手动更换开关.当驾驶员从路口A驶向路口B时,他/她尝试选择将他/她不得不手动更换开关的次数最小化的路线. 编写一个程序,该程序将计算从交点A到交点B所需的最小开关更改次数.第i个交点处的开关最初指向列出的第一个交点的方向. 分析:对于某点i,去往其直接可到达的点列表中的第一个点时不需要更换开关,等价于边长为0:而其他的点需要更换开关,等价于边长为1.dijkstra裸题. #in…
1.poj  1847  Tram   最短路 2.总结:用dijkstra做的,算出a到其它各个点要改向的次数.其它应该也可以. 题意: 有点难懂.n个结点,每个点可通向ki个相邻点,默认指向第一个相邻点,可以改变指向.求一条从A到B的路,使用最少改变路上点的指向的次数. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm>…
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 it can leave…
Tram Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11771   Accepted: 4301 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…
题目链接:https://vjudge.net/problem/POJ-1847 思路:想从A到B使用开关少,想清楚了就是个简单的最短路,可以把不用开开关为权值0, 要开开关为权值1,就是求A到B开开关最少的次数,题目说了,每行第一个点是第 i-th点和他正好数开关开的方向连接. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <…
#include<iostream> #include<algorithm> #include<queue> #include<cstdio> #include<cstring> using namespace std; ,INF=0x3f3f3f3f; int h[N],e[N],v[N],w[N],ne[N],idx; int dist[N]; bool st[N]; int n,beg,en,ans; void add(int a,int…
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 ][];…
POJ 无限循环CE中.感觉是读题难.然后就可以建图上模板了. 附个人代码: #include<stdio.h>#include<string.h>#include<iostream>#define maxn 0x1f1f1f1f#define size 210using namespace std; int low[size];bool used[size];int map[size][size];int n, a, b; void init(){    for (i…
Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24979   Accepted: 8114 Description Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her,…
XYZZY Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3105   Accepted: 887 Description The prototypical computer adventure game, first designed by Will Crowther on the PDP-10 in the mid-1970s as an attempt at computer-refereed fantasy ga…
Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13800   Accepted: 5815 Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currenc…
Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22557   Accepted: 7339 Description Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her,…
模板题辣很简单的 只有两种val 0 和1 #include <iostream> #include <string> #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <vector> #include <set> #include <algorithm> #define INF 0x3F…
#include<stdio.h> #include<string.h> #include<limits.h> #include<queue> using namespace std; #define N 5505 #define M 55000//注意边和点集的数组大小 struct edge { int to,value,next; }edges[M]; ; int addedge(int u,int v,int w) { edges[len].to=v…
Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 30169   Accepted: 10914 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way p…
前面用dijstra写过了.但是捏.数据很小.也可以用Floyd来写. 注意题目里给出的是有向的权值. 附代码:#include<stdio.h>#include<string.h>#include<iostream>#define inf 0x1f1f1f1fusing namespace std; int n, a, b;int num;int dis[210][210];int i, j, k; int main(){    while (cin >>…
Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26395   Accepted: 14558 Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst th…
链接:最短路 A.HDU 2544    最短路 算是最基础的题目了吧.............我采用的是Dijkstra算法....... 代码: #include <iostream> #include <cstring> #include <cstdio> using namespace std; #define inf 0x3f3f3f3f ][],d[],vis[],n,m; int Dijkstra() { memset(vis,,sizeof(vis));…
求一个图最短路边的办法.好像下面的那个有问题.单向边和双向边一定是有区别的.这个比较容易.参照该文的最短路网络流题目和连通图题目一题求最短路关节边 另外上述2个题目的代码好像有问题. 在UVALIVE 6885中不能得到AC.不知道原因.感觉是对的. 另一种判断最短路的方法就是 从起点到u+从终点到v+边U,V权值==最短路值那么这条边为最短路 这种方案的代码 ; i <= M ; i++) { scanf("%d%d%d",&u[i],&v[i],&w[…