摘要: 题目链接求单源最短路的题,因为边权非负,所以可以用dijkstra。这题有一点需要注意的地方是有重边,在读数据时取较小的即可。View Code 1 #include <stdio.h> 2 #include <string.h> 3 #define MIN(a,b) ((a)<(b)?(a):(b)) 4 #define N 200 5 #define INF 2000000 6 int g[N][N]; 7 int dist[N]; 8 int n,m; 9 char vis[N];10 void dijkstra(int u)11 {12 int i,min 阅读全文
posted @ 2012-04-20 23:06 BeatLJ 阅读(221) 评论(0) 推荐(0) 编辑
摘要: 题目链接这题与HDOJ1879有点不太一样,不能把不符合条件的边看成是已经修好的,使用克鲁斯卡尔时,碰到不符合的边直接跳过即可。View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 #define D(x1,y1,x2,y2) (sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))) 5 #define N 101 6 #define M 5000 7 int x[N],y[N]; 8 struct node 9 {10 int a,b;11 阅读全文
posted @ 2012-04-20 22:21 BeatLJ 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 题目链接最小生成树的题。克鲁斯卡尔算法。View Code 1 #include <stdio.h> 2 #define N 100 3 #define M 5000 4 struct node 5 { 6 int a,b,d; 7 }edge[M]; 8 int n; 9 int p[N];10 void make_set()11 {12 int i;13 for(i=1;i<=n;i++) p[i]=i;14 }15 int find_set(int i)16 {17 return i==p[i]?p[i]:(p[i]=find_set(p[i]));... 阅读全文
posted @ 2012-04-20 21:23 BeatLJ 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 题目链接最小生成树的题。我用的克鲁斯卡尔算法。View Code 1 #include <stdio.h> 2 #define N 100 3 #define M 5000 4 struct node 5 { 6 int a,b,d; 7 }edge[M]; 8 int n,m; 9 int p[N];10 void make_set()11 {12 int i;13 for(i=1;i<=n;i++) p[i]=i;14 }15 int find_set(int i)16 {17 return i==p[i]?p[i]:(p[i]=find_set(p[... 阅读全文
posted @ 2012-04-20 21:07 BeatLJ 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 题目链接题目大意:给定n个整数,接下来有m个操作,操作分为两类,一类是修改操作:将第i个数改为k,另一类是查询操作:询问i,j之间第k大的数是多少。对于每个查询操作输出结果。如果没有修改操作,可以直接用伴随数组来做。跟POJ2104那题一样。这里的关键是修改操作,如果每次修改后都进行排序的话,肯定挂掉,注意到我们这里每次只修改一个数,只需将修改的数排到正确的位置即可,可以使用链表实现。这题的纠结之处在于数据格式,读入处理不好可能会WA或者RE。View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #define N 阅读全文
posted @ 2012-04-20 20:44 BeatLJ 阅读(273) 评论(0) 推荐(0) 编辑