HDU 2224 The shortest path】的更多相关文章

The shortest path Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1507    Accepted Submission(s): 773 Problem Description There are n points on the plane, Pi(xi, yi)(1 <= i <= n), and xi < x…
题目链接: Hdu 4725 The Shortest Path in Nya Graph 题目描述: 有n个点,m条边,每经过路i需要wi元.并且每一个点都有自己所在的层.一个点都乡里的层需要花费c元,问从1到N最小花费? 解题思路: 建图比较楠,刚开始的时候想到拆点,把一个点拆成两个,N+i表示点i所在层,对每个点对自己所在层建双向边,权值为0. 然后相邻层建双向边,权值为c.对w条点之间的边,正常建.但是写出来样例都GG了.发现对于同一层的点,在我建的图中可以免费来回跑,这样好像和题意有些…
HDU - 4725 The Shortest Path in Nya Graph http://acm.hdu.edu.cn/showproblem.php?pid=4725 This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not und…
he Shortest Path in Nya Graph Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 472564-bit integer IO format: %I64d      Java class name: Main   This is a very easy problem, your task is just calculate el camin…
The Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3164    Accepted Submission(s): 1030 Problem Description There are N cities in the country. Each city is represent by a matrix s…
Description This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just move on. The Nya graph is an undirecte…
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13445    Accepted Submission(s): 2856 Problem Description This is a very easy problem, your task is just calculate…
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 37    Accepted Submission(s): 6 Problem Description This is a very easy problem, your task is just calculate el cam…
Description This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just move on.  The Nya graph is an undirect…
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11694    Accepted Submission(s): 2537 Problem Description This is a very easy problem, your task is just calculate…
This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just move on. The Nya graph is an undirected graph with…
This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just move on. The Nya graph is an undirected graph with…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题意:n个点,某个点属于某一层.共有n层.第i层的点到第i+1层的点和到第i-1层的点的代价均是C.另外有一类边连接两个点u.v,代价w.求1到n的最短路. 思路:拆点.n个点不动,编号1到n.将n层每层拆成两个点,第i层拆成n+i*2-1,n+i*2.相邻的层连边(n+i*2-1,n+(i+1)*2,C),(n+(i+1)*2-1,n+i*2,C).若顶点u属于第i层,连边(u,n+i*2-…
http://acm.hdu.edu.cn/showproblem.php?pid=2807 第一次做矩阵乘法,没有优化超时,看了别人的优化的矩阵乘法,就过了. #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #define maxn 100 using namespace std; <<; int n,m,t1,x,y; int g[ma…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题意:有N个点和N层..一层有X个点(0<=X<=N).两邻两层间有一条路花费C.还有M条小路在两个点之间.问从第一个点走到第N个点最短路是多少... 题解:依然是在点之间SPFA.不过在跑的时候不仅要跑与当前点相连接的点.还有把当前点所在层的相邻层的点判断是否加入队列... CODE: #include<cstdio> #include<cmath> #include&…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题目大意:有n层,n个点分布在这些层上,相邻层的点是可以联通的且距离为c,还有额外给出了m个条边,求1号点到n号点的最短距离,若无法到达则输出“-1”. 解题思路:最短路问题,主要是建图很难.如果按常规建法,用邻接表存每层的节点编号然后在建边肯定会超时,因为如果点只分布在两个层上,那建边的复杂度就是O(n^2)了.所以要改变一下思路,可以用n个虚拟点来代表n层,把连到该层的点都连接到虚拟点上,…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题意:有n个点和n层,m条边,每一层的任意一个点都可以花费固定的值到下一层或者上一层的任意点 然后m条边链接的点可以花费给出的值进行转移,最后问从i点到n点最少要花费多少. 这题点的个数有100000,层数也是100000,不算额外边暴力建边肯定要爆. 所以可以把层数也当成一个点比如说i点在j层于是n+j就与i链接花费0然后i点可以和上下层任意一个点链接 及i与n+j+1链接i与n+j-1链接…
<题目链接> <转载于  >>> > 题目大意: 每个点放在一层,然后给了n个点,相邻的两层距离是固定的c,有额外m条无向边,然后求1到n的最短路径,如果没有则输出-1 . 解题分析: 本题建图是关键,需要注意的是,每一层不一定只有一个点.因此,如果两层之间建边时只是简单将上面的所有点的相互连接,那么取极端情况,当只有两层并且每层只有50000个点时,在O(N^2)的复杂度下,光是建图就已经爆了.所以我们对每一层进行拆点,但是如果每一层只拆成一个点的话,那么该层每…
题意:给你n个点,m条无向边,每个点都属于一个层,相邻层的任意点都能花费C到另一层任意点,问你1到n最小路径 思路:没理解题意,以为每一层一个点,题目给的是第i个点的层数编号.这道题的难点在于建边,如果用最朴素的相邻层所有点互相连接,那么可能有5*10^4连5*10^4,复杂度O(n^2).这里我们用拆点(?大概),把每一层拆出一个点,作为每一层点和相邻层连接的中转站.这里要特别注意,同一层的点的距离不是0,所以我们建边不能全是无向边: 1.层与层无向边,权值C 2.层与同层点建单向边,权值0…
题意:N个点,每个点有一个层号L,相邻的两层 Li 与 Li+1 之间的距离为C.另外给出M条无向边,求从点1到点N的最短路. 分析:同一层之间的两点距离并不是0,这是一个小坑.依次把相邻两层的所有点连边会导致复杂度很高.可以将每一层看作一个点,但是把它和层中的点连边会导致同层的两点距离为0. 为了避免这种情况,可以将每层拆作两点,表示入点和出点.所以所建图中一共有3N个点.1~N为原图中的点,N+1~2*N为每层出点,2*N+1~3*N为每层入点.对每个在该层中的点u,将其连至出点N+i:再将…
主要是建图,建好图之后跑一边dijkstra即可. 一共3N个点,1~N是原图中的点1~N,然后把每层x拆成两个点(N+x)[用于连指向x层的边]和(N+N+x)[用于连从x层指出的边]. 相邻层节点互相可达:AddEdge( N+N+x+1, N+x, C), AddEdge( N+N+x, N+x+1, C); 对于位于x层的节点i,AddEdge(N+x, i, 0), AddEdge(i, N+N+x, 0); #include <cstdio> #include <cstrin…
HDU 4725 The Shortest Path in Nya Graph : http://acm.hdu.edu.cn/showproblem.php?pid=4725 题意: 在一个图中跑最短路,这个图中的每一个点都有一个等级,每次都只能向高一个等级或低一个等级的点跑.问最短的距离. 思路: 参考/kuangbin 这道题自己一开始直接按等级枚举,发现这样的复杂度是n*n的.需要更加合理的建图.考虑给每个等级建立两个点,一个用于进,一个用于出. 第i层,入边到N+2*i-1, 出边从N…
题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=3631 Shortest Path Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3962    Accepted Submission(s): 9…
Shortest Path 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5636 Description There is a path graph G=(V,E) with n vertices. Vertices are numbered from 1 to n and there is an edge with unit length between i and i+1 (1≤i<n). To make the graph more in…
Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 627    Accepted Submission(s): 204 Problem Description There is a path graph G=(V,E) with n vertices. Vertices are numbered from 1…
Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1146 Accepted Submission(s): 358 Problem Description There is a path graph G=(V,E) with n vertices. Vertices are numbered from 1 to…
Problem Description This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just move on.The Nya graph is an un…
Shortest Path Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u SubmitStatus Description When YY was a boy and LMY was a girl, they trained for NOI (National Olympiad in Informatics) in GD team. One day, GD team's coach, Prof. G…
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que camb…
The Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2440    Accepted Submission(s): 784 Problem Description There are N cities in the country. Each city is represent by a matrix si…