[HDOJ5521]Meeting(最短路)】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 给n个点,m个块.块内点到点之间话费的时间ti.两个人分别从点1和点n出发,问两人是否可以相遇,并求出相遇最短时间和路径,路径按照字典序输出. 这题的难点在于处理块内的点到块外点的关系.我们可以添加一个“集合点”,此点到集合内各点距离为w,点到此集合的距离为0建图. 从1和n分别做一次最短路,找到每一个距离最长的点(即为相遇点),记下长度再枚举两个结果,看一共多少个相遇点 #include <…
题目链接: Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2024    Accepted Submission(s): 628 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farm…
Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3361    Accepted Submission(s): 1073 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer Jo…
Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 6865    Accepted Submission(s): 2085 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer Jo…
http://acm.hdu.edu.cn/showproblem.php?pid=5521 题目大意:A,B两个人分别在1和n区.给出区之间有联系的图以及到达所需时间.求两个人见面最短时间以及在哪个区碰面(可有多个).多个区被当成一个集合(set),集合中的点互相到达时间相同,并且一定能互达. 思路:在于边的数量庞大.需要着手解决的问题是如何建图使得边的数目减小. 题目的特殊点在于:每个区域内部的点点距离是相同的. 所以,构造虚拟结点,解决边数过多的问题. (n*(n-1))/2 ------…
题意:有N个点,给定M个集合,集合Si里面的点两两之间的距离都为Ti,集合里面的所有点数之和<=1e6.有两个人分别在1和N处,求1个点使得两个人到这一点距离的最大值最小 思路:这题是裸的最短路问题,难点在建图.然而建图也只有1步,在集合外新建1个点,每个点向它连一条Ti/2的边(避免浮点数,可以先乘2,然后结果除以2).如此巧妙... #include <bits/stdc++.h> using namespace std; #define X first #define Y seco…
题意:有n个点,m个点集,每个点集中有e[i]个点,同一点集的点互相之间到达需要t[i]单位的时间,求min(max(dis(1,i),dis(i,n))),i属于[1,n] 输出最小值并増序输出所有使答案取到最小值的i,无解输出Evil John n<=1e5,1<=t[i]<=1e9,sigma e[i]<=1e6 思路:出烂了的裂点最短路 对于每个点集另外裂一个点id,设该点集中的点为a[i] a[i]——>id 长度为t[i] id——>a[i] 长度为0 以1…
Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1358    Accepted Submission(s): 435 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer Jo…
Meeting Time limit: 2.0 secondMemory limit: 64 MB K friends has decided to meet in order to celebrate their victory at the programming contest. Unfortunately, because of the tickets rise in price there is a problem: all of them live in different part…
http://acm.hdu.edu.cn/showproblem.php?pid=5521 Meeting Problem Description   Bessie and her friend Elsie decide to have a meeting. However, after Farmer John decorated hisfences they were separated into different blocks. John's farm are divided into …
题意:有N个点,两个人,其中一个人住在点1,另一个人住在点n,有M个点集,集合内的数表示任意两点的距离为dis ,现在问,如果两个人要见面, 需要最短距离是多少,有哪几个点能被当成见面点. 析:分别对1和n进行最短路操作,这个题最让人别扭的就是边太多,如果你直接全部都存下来,那么一定会MLE,所以一定要优化边.所以我们要把每一行的边都记下来, 而不是两两都记下,然后把每一行的编号记下来,最后要查询时,就行编号去定位到哪一行,这样就不会超内存.这里会了,其他的就很简单了. 代码如下: #pragm…
题意:给出几个集合,每个集合中有Si个点 且任意两个点的距离为ti,现在要求两个人分别从1和n出发,问最短多长时间才能遇到,且给出这些可能的相遇点; 取两个人到达某点时所用时间大的值 然后取最小的  若有多个结果 则按点的升序排列 解析: 比较裸的最短路 ,但坑在建图上,Si的和小于1e6  那么建的边肯定会超内存  所以压缩一下,把每个集合看作一个点  集合中的点到集合的距离为0  集合到集合中的点的距离为ti   即入为0 出为ti    然后普通最短路求就好了 spfa: #include…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 题意:有1-n共n个点,给出m个块(完全图),并知道块内各点之间互相到达花费时间均为ti.已知两人分别在点1和点n,求在哪些点相遇能使得花费时间最短.题解:显然先想到从点1和点n分别求最短路,然后枚举点找出哪些点是相遇花费时间最少的.但是这题边太多了,假设一个完全图里有x个点,那边就有x*(x-1)/2条了,必须化简其边.一个可行的办法是给每个完全图增加两个点,分别为入点和出点,入点向其中的点…
今天旁观了Angry_Newbie的模拟区域赛(2015shenyang) 倒着看最先看的M题,很明显的最短路问题,在我看懂的时候他们已经开始敲B了. 后来听说D过了很多人.. D题一看是个博弈,给了很多组样例,找找规律懵一懵就ac了.然后我就滚粗了... 而他们也早就A了D,很快他们又A了B... 后来就全程看着罗大神敲无限TLE的M.感觉算法肯定没错,但是想不到哪里还可以优化. 后来我滚了之后听说他们也成功AC了M. 下来仔细想想M也并不是难题,如果平时做的话,肯定不会卡那么久的... A…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 题目大意: 有 \(n\) 个点 \(m\) 个集合,一个点可能处于若干个集合内,属于第 \(i\) 个集合的任意两点间的距离是 \(t_i\) ,点 \(1\) 是起点,点 \(n\) 是终点. 你现在需要找到所有点中到 \(1\) . \(n\) 两点的距离的较大值的最小值,并输出所有满足要求的点. 解题思路: 这道题目难的不是最短路,而是建图. 因为最多可能有 \(n\) 个点在同一个集…
题意:有\(n\)个点,\(m\)个集合,集合\(E_i\)中的点都与集合中的其它点有一条边权为\(t_i\)的边,现在问第\(1\)个点和第\(n\)个点到某个点的路径最短,输出最短路径和目标点,如果不满足条件则输出\(Evil John\). 题解:题目所给的边数关系太复杂了,我们可以让每个集合中的所有点都与一个虚拟节点连边,而这些点两两却不连,然后再去找\(1\)个和第\(n\)个点的最短路径,不难发现,最终得到的路径为\(dis[i]/2\),所以我们只要用虚拟节点建边然后跑两次dijk…
Black Spot Time limit: 1.0 secondMemory limit: 64 MB Bootstrap: Jones's terrible leviathan will find you and drag the Pearl back to the depths and you along with it. Jack: Any idea when Jones might release said terrible beastie? Bootstrap: I already…
Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1656    Accepted Submission(s): 515 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer Joh…
Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer John decorated hisfences they were separated into different blocks. John's farm are divided into n blocks labelled from 1 to n.Bessie lives in the first b…
Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 4542    Accepted Submission(s): 1436 Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer Jo…
SAMER08A - Almost Shortest Path #graph-theory #shortest-path #dijkstra-s-algorithm Finding the shortest path that goes from a starting point to a destination point given a set of points and route lengths connecting them is an already well known probl…
不定时更新博客,该博客仅仅是一篇关于最短路的题集,题目顺序随机. 算法思想什么的,我就随便说(复)说(制)咯: Dijkstra算法:以起始点为中心向外层层扩展,直到扩展到终点为止.有贪心的意思. 大部分题用Dij+队列优化都能解决..但有负权边不行哦. Bellman-Ford:反复对边集E中的每条边进行松弛操作. 求含负权图(有负环输出错误提示)的单源最短路径,效率很低,至于对多余松弛的优化就是设置个标记,还是很慢,不如写SPFA. 判断负环:在每次松弛时把每条边都更新一下,若在n-1次松弛…
WuKong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1800    Accepted Submission(s): 670 Problem Description Liyuan wanted to rewrite the famous book “Journey to the West” (“Xi You Ji” in Chin…
传送门 题目 Bessie and her friend Elsie decide to have a meeting. However, after Farmer John decorated his fences they were separated into different blocks. John's farm are divided into n blocks labelled from 1 to n.Bessie lives in the first block while E…
Bessie and her friend Elsie decide to have a meeting. However, after Farmer John decorated his fences they were separated into different blocks. John's farm are divided into nn blocks labelled from 11 to nn. Bessie lives in the first block while Elsi…
POJ 1161 Walls(最短路+枚举) 题目背景 题目大意:题意是说有 n个小镇,他们两两之间可能存在一些墙(不是每两个都有),把整个二维平面分成多个区域,当然这些区域都是一些封闭的多边形(除了最外面的一个),现在,如果某几个小镇上的人想要聚会,为选择哪个区域为聚会地点,可以使他们所有人总共需要穿过的墙数最小,题目上有说明,不在某个点上聚会(聚会点在某个多边形内部),行进过程中不穿过图中的点(也就是除出发点外的其他小镇). 输入第1行代表m(2<=M<=200)个区域 第2行代表n(3&…
HDU5521 Meeting 题意: 给你n个点,它们组成了m个团,第i个团内有si个点,且每个团内的点互相之间距离为ti,问如果同时从点1和点n出发,最短耗时多少相遇 很明显题目给出的是个无负环的图,且要跑出单源最短路,那不就是个dij吗 大方向定下,但图该怎么建呢? way1: 给每个团内的所有点两两暴力建边 如图所示:黑的为点,红的为团,相同颜色的边长度相等 共 \(\sum ^{m}_{i=1}\dfrac {1}{2}s_{i}\left( s_{i}-1\right)\) 条边 而…
Liyuan wanted to rewrite the famous book "Journey to the West" ("Xi You Ji" in Chinese pinyin). In the original book, the Monkey King Sun Wukong was trapped by the Buddha for 500 years, then he was rescued by Tang Monk, and began his j…
Recently, Shua Shua had a big quarrel with his GF. He is so upset that he decides to take a trip to some other city to avoid meeting her. He will travel only by air and he can go to any city if there exists a flight and it can help him reduce the tot…
http://www.lydsy.com/JudgeOnline/problem.php?id=1001 思路:这应该算是经典的最大流求最小割吧.不过题目中n,m<=1000,用最大流会TLE,所以要利用平面图的一些性质. 这里讲一下平面图的对偶图性质. 在平面图中,所有边将图分成了n个平面.我们将平面标号,对于原图中的每条边,在与之相邻的两个平面间连一条边,最后得到的图就是原图的对偶图. 对偶图有如下性质: 1.对偶图的边数与原图相等. 2.对偶图中的每个环对应原图中的割. 于是可以在原图中的…