基础图论
文章平均质量分 74
nianiajr
http://www.liangjiarui.com/
展开
-
uva 439 - Knight Moves
A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a chessboa原创 2013-07-31 16:18:26 · 590 阅读 · 0 评论 -
poj1062
遍历+dijsktra,注意每次可以使用的更新点的筛选#include#include#include#include#include#includeusing namespace std;const int INF=0x3f3f3f3f;int m,n,t,v;int p[105],l[105],x[105],vis[105],ans,d[105];struct ed原创 2013-12-21 11:45:27 · 761 阅读 · 0 评论 -
poj1860
bellman判环:#include#include#include#includeusing namespace std;struct edge{ int from; int to; double r; double c;}es[250];int n,m,s,E;double v,a,b,rab,rba,cab,cba,d原创 2013-12-21 11:38:10 · 733 阅读 · 0 评论 -
poj3259
依旧是判环,不过需要注意的是边的设定#include#include#include#includeusing namespace std;struct edge{ int from; int to; int v;}es[6000];int n,m,w,f,s,e,t,E,d[505];bool find_loop(){ memset(d,原创 2013-12-21 11:41:07 · 784 阅读 · 0 评论 -
关于基本最短路求解总结
最近数据结构也要考试来着,所以把最短路的一些基础题给做了一下,大概就以下几种方法:1.floyd算法:嵌套三个循环,利用离散的求关系传递闭包的逻辑关系,可求两点直接的最短路径,不过复杂度在O(n^3),一般用在n比较小的时候,在判断流通货币等问题时,利用floyd也可以起到良好效果,因为利用bellman当然也可以判断是否有回路,但要判断这个回路是否可以产生流通差价还是需要一些特定处理的,原创 2013-12-21 11:35:35 · 895 阅读 · 0 评论 -
poj1094
这个拓扑排序有一些特殊,在给出m个信息时,只要前r个信息已经足够判断的时候就要输出判断结果,但输入还要继续,这是Poj的风格了,不过判断时一定要小心优先级,要先判断是否有环,然后是否有唯一序列,最后才是不确定序列,这里我坑了太久,看了别人的提示才知道。拓扑排序做法就是按照找入度为0的点作为起始点进行排序,这里有bfs较为贴切。总归来说还是要细心,理解逻辑的先后顺序。#include#incl原创 2013-12-29 13:57:58 · 658 阅读 · 0 评论 -
hdu 4751
一个人就是弱···做这个题做了四个小时···一直WA开始以为两个动态数组当作两个组,依次把每个人加入就好,还真觉得没什么问题。。。思维好搓啊,哪里可以这么简单。后面下来才知道这是一个tow_sat问题,第一次听说这个名词···,大概和二分图差不多,既然要分组,那么不认识的肯定不能在同一组,用两个标记进行排斥分组就好,但得注意此处的单方认识也要当作不认识,后面枚举每个点进行一遍dfs()查找是否有矛原创 2013-09-22 11:59:44 · 728 阅读 · 0 评论 -
hdu 4738
判连通求桥问题,输出最少派兵人数,不过有个坑就在于如果有桥上无人把手也应当需要派一个人去炸桥,则问题可以解决。#include#include#include#includeconst int INF = 0x3f3f3f3f;const int maxn = 1005;using namespace std;int edge[maxn][maxn];vector原创 2013-10-03 10:16:30 · 818 阅读 · 0 评论 -
URAL 1022 拓扑排序
题目要求长辈有分,子孙不能排在长辈前面,输出顺序,那么这样来看这就是一个拓扑排序题,开始以为是一个求路径最大的问题,不过存在两节点间并没有关系WA了一次,后面再想题目好像有多解,只要输出一种方案即可,那么细想一下这就是一个拓扑排序了,只要利用dfs回溯从后往前排,把每个结点的子孙往后排,然后不断将访问结束的点插入到首部就好,由于这里明确是一个有向无环图(DAG),所以还可以省略判断直接排序。#原创 2013-09-11 11:38:59 · 906 阅读 · 0 评论 -
Pet
一个基础的图,dfs就好了,找出距离超过d的就行,因为在d范围内并没有捕捉到小仓鼠。#include#include#include#includeusing namespace std;vectorm[100005];int vis[100005];int sum,dis;void dfs(int x,int d){ vis[x]=1; if(d>di原创 2013-09-08 23:39:59 · 836 阅读 · 0 评论 -
poj 1556 判线段相交+最短路问题
此题就是给出一幅图,然后上面一些墙,让求起点到终点的最短路径,说到最短路径那就必须得有一个图,那么首要问题就变成了如何构图,这里就得用到计算几何里面的基础知识,判断线段是否相交,也就是两点之间的连线,是否和墙相交,相交就没有路,不相交就有路,这样一来枚举任意两个点作判断便可成图,后面有图了就变成求最短路的问题,最近才学的,所以写两种吧,当作一种复习:1.Dijkstra 求最短路:#inc原创 2013-08-16 01:33:35 · 754 阅读 · 0 评论 -
uva 10596 - Morning Walk
Kamal is a Motashota guy. He has got a new job in Chittagong. So, he has moved to Chittagong from Dinajpur. He was getting fatter in Dinajpur as he had no work in his hand there. So, moving to Chittag原创 2013-08-01 16:18:42 · 646 阅读 · 0 评论 -
uva 784 - Maze Exploration
A maze of rectangular rooms is represented on a two dimensional grid as illustrated in figure 1a. Each point of the grid is represented by a character. The points of room walls are marked by the same原创 2013-08-02 00:47:50 · 655 阅读 · 0 评论 -
uva 532 - Dungeon Master
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south原创 2013-08-01 21:48:41 · 649 阅读 · 0 评论 -
uva 10004 - Bicoloring
In 1976 the ``Four Color Map Theorem" was proven with the assistance of a computer. This theorem states that every map can be colored using only four colors, in such a way that no region is colored us原创 2013-08-01 13:55:16 · 723 阅读 · 0 评论 -
uva 10305 - Ordering Tasks
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed.InputThe input will consist of several原创 2013-07-31 21:01:37 · 770 阅读 · 0 评论 -
poj2253
floyd变形,求最短路径最大值#include#include#include#includeusing namespace std;struct point{ double x,y;}p[205];double g[250][250];const double INF=100000000.0;int n;double dis(point p1,point原创 2013-12-21 11:47:28 · 671 阅读 · 0 评论