最短路 || POJ 1847 Tram】的更多相关文章

POJ 1847 最短路 每个点都有初始指向,问从起点到终点最少要改变多少次点的指向 *初始指向的那条边长度为0,其他的长度为1,表示要改变一次指向,然后最短路 =========高亮!!!==========数组要开n^2的QAQ #include <iostream> #include <cstdio> #include <queue> using namespace std; #define SZ 10005//开n^2的数组!! #define INF 1e9+…
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…
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…
题意很好懂,但是不好下手.这里可以把每个点编个号(1-25),看做一个点,然后能够到达即为其两个点的编号之间有边,形成一幅图,然后求最短路的问题.并且pre数组记录前驱节点,print_path()方法可用算法导论上的. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <ve…
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…
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…
题意:给出n个站点,每个站点都有铁路通向其他站点 如果当前要走得路恰好是该站点的开关指向的铁路,则不用扳开关,否则要手动扳动开关,给出起点和终点,问最少需要扳动多少次开关 输入的第一行是n,start,end 接下来的n行,每一行中,第一个数是该站点向外连接的铁路条数, 第二个数是该站点的开关指向的铁路(因为这儿没有读懂= =所以都建不出图来--5555参见这一句话:Switch in the i-th intersection is initially pointing in the dire…
题目传送门 题意:这题题目难懂.问题是A到B最少要转换几次城市.告诉每个城市相连的关系图,默认与第一个之间相连,就是不用转换,其余都要转换. 分析:把第一个城市权值设为0, 其余设为0.然后Floyd跑一下,得到A到B最少转换几次.有点水 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 1e2 + 5; const int INF =…
分析: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>…
题目链接:https://vjudge.net/problem/POJ-1847 思路:想从A到B使用开关少,想清楚了就是个简单的最短路,可以把不用开开关为权值0, 要开开关为权值1,就是求A到B开开关最少的次数,题目说了,每行第一个点是第 i-th点和他正好数开关开的方向连接. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <…
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…
#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 ][];…
C - 昂贵的聘礼 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1062 Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家 拿不出这么多金币,便请求酋长降低要求.酋长说:"嗯,如果你能够替我弄到大祭司的皮袄,…
题目传送门 题意:从(0, 5)走到(10, 5),中间有一些门,走的路是直线,问最短的距离 分析:关键是建图,可以保存所有的点,两点连通的条件是线段和中间的线段都不相交,建立有向图,然后用Dijkstra跑最短路.好题! /************************************************ * Author :Running_Time * Created Time :2015/10/24 星期六 09:48:49 * File Name :POJ_1556.cpp…
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…
Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place…
从点N到1的最短路 *记得无向图两个方向都要建边就好了…… 以及多组数据= = #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; #define SZ 4005 #define INF 1e9+10 ; struct edge { int t,d; }l[SZ]; void build(int f,int t,int d…
模板题辣很简单的 只有两种val 0 和1 #include <iostream> #include <string> #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <vector> #include <set> #include <algorithm> #define INF 0x3F…
前面用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 >>…
 #include <algorithm>#include <queue>#include <cstdio>#include <cstdlib>#include <cstring>#include <cctype>#include <cmath>#include <queue>#include <vector>#define N 1010#define INF 0x3f3f3f3f#define M…
已知图中从一点到另一点的距离,从1号点到另一点再从这一点返回1号点,求去到所有点的距离之和最小值 *解法:正着反着分别建图,把到每个点的距离加起来 spfa跑完之后dist数组就是从起点到每一点的最短距离 get反着建图这种技能 #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; #define SZ 1000005 #d…
求一个图最短路边的办法.好像下面的那个有问题.单向边和双向边一定是有区别的.这个比较容易.参照该文的最短路网络流题目和连通图题目一题求最短路关节边 另外上述2个题目的代码好像有问题. 在UVALIVE 6885中不能得到AC.不知道原因.感觉是对的. 另一种判断最短路的方法就是 从起点到u+从终点到v+边U,V权值==最短路值那么这条边为最短路 这种方案的代码 ; i <= M ; i++) { scanf("%d%d%d",&u[i],&v[i],&w[…
训练赛20151122 5:00:00     Overview Problem Status Rank Discuss Current Time: 2015-11-23 17:33:18 Contest Type: Public Start Time: 2015-11-22 08:30:00 Contest Status: Ended End Time: 2015-11-22 13:30:00 Manager: hrbustacm Clone this contest     ID Origi…
链接:最短路 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));…