上一页 1 ··· 3 4 5 6 7
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3790方法:用建立有向图的方式建立无向图,调用dijkstra的时候,在优先队列里面的比较以及对边的松弛,都要依次根绝两种权值进行比较。感想:简单题。代码:View Code #include<iostream>#include<queue>//#include<algorithm>using namespace std;int const MAX =0x3f3f3f3f;int cityCount,roadsCount;struct Arc{ int vetex 阅读全文
posted @ 2013-04-15 00:38 kbyd 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874方法:使用邻接表,将两个点之间的所有边都用一条最小费用的边来代表。然后用这些边来建立图并调用DIJKSTRA,最后判断到目标定点的距离是不是正无穷,不是正无穷的值就是最小路径的费用权值。感想:用数组每次排序没有在选择的点的方法来模拟优先队列不好,以后要用堆来模拟。代码:View Code #include<iostream>#include<algorithm>using namespace std;int const MAX =0x3f3f3f3f;int cityC 阅读全文
posted @ 2013-04-15 00:33 kbyd 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1269方法:就是求强连通分支个数,为1就可以。感想:《算法导论》上额强连通分支部分的定理证明有必要多理解。代码:View Code #include<iostream>#include<algorithm>using namespace std;//int const MAX =0x3f3f3f3f;int const MAX = 10005;struct Arc{ int vetex; Arc* nexttArc;};struct Node{ int x; Arc* fir 阅读全文
posted @ 2013-04-13 23:33 kbyd 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647方法:该题需要贪心,即工资最低的直接取888的基本工资,而A的工资>B的工资 则A只比B多1. 实现方法是将输入的工资大于关系转换成小于关系,然后利用小于关系建立有向图的边。如输入a b(表示a工资比b高),则建立一个b到a的有向边(表示b工资比a低。建好图后,利用拓扑排序的方式,先把最开始的入度为0的顶点的工资设置为最低工资,删除该顶点后将其指向的节点 工资在刚才那个入度为0的基础上加1,入度减1,如果入度减少为0了,又同样迭代,本代码使用队列来实现该中迭代,有点类似广搜的方式。在拓扑 阅读全文
posted @ 2013-04-13 23:27 kbyd 阅读(290) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301方法:直接建模后用prim算法感想:简单题代码:#include<iostream>#include <queue>using namespace std;struct fuckNode{ int index; int distance;}; struct cmp{ bool operator ()(fuckNode x, fuckNode y) { return x.distance> y.distance; // x小的优先级高 }}; int... 阅读全文
posted @ 2013-04-13 22:15 kbyd 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1875方法:在往优先队列中加入定点的时候,判断当前队列出来的点探寻到其时到其的距离是否满足限制条件,不满足,该顶点就不进优先队列,相当于该边在图里不存在。感想:简单题。代码:View Code #include<iostream>#include<queue>#include<math.h>using namespace std;int const MAX =0x3f3f3f3f;struct Node { int x; int y; double distanc 阅读全文
posted @ 2013-04-13 21:30 kbyd 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1325方法:建好有向图后,要判断是否是树,关键判断两点,即1,是否只有一个唯一的根节点;2,是否从根到任何节点都有且仅有一条路径。这就要就图中入度为0的定点有且仅有一个,其他的定点入度只能是1.感想:简单题。代码:View Code #include<iostream>using namespace std;const int MAX = 100005;int indegree[MAX];int main(){ int a,b; int i=0,j=0,kk=0; memset(i... 阅读全文
posted @ 2013-04-13 19:04 kbyd 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1181方法:以所有咒语看做一条起点为首字母,终点为末字母的有向边来建立有向图。然后在图中判断目标路径是否存在,判断的方法是 :如果目标路径的起点和终点不都在图中出现,则直接得出不存在该路径,否则广搜索来判断目标路径是否存在。感想:简单题目,但后期需要频繁重温代码以熟悉广搜代码的写法。该题使用的是邻接矩阵。代码:View Code #include<iostream>#include<queue>using namespace std;bool matrix[26][26];b 阅读全文
posted @ 2013-04-13 17:43 kbyd 阅读(227) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7