2012年7月12日

Bellman-ford

摘要: Bellman-ford 算法View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int mp[210][210];int dis[210];int N, M;const int inf = 0x7f7f7f7f;void bellman_ford( ){ //初始话 for( int i = 1; i <= N; i++) { dis[i] = inf; } dis[1] = .. 阅读全文

posted @ 2012-07-12 21:58 more think, more gains 阅读(146) 评论(0) 推荐(0) 编辑

poj 3026

摘要: 算法:1.刚开始自己的算法是一次BFS,求出各点距离,建好图,但是提交上去一直WA,不解。2.修正算法枚举所有A与S点,AC。。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<queue>#include<iostream>using namespace std;struct node{ int a, b, num; bool operator < ( const node& 阅读全文

posted @ 2012-07-12 14:04 more think, more gains 阅读(147) 评论(0) 推荐(0) 编辑

poj 1258

摘要: 原来POJ上也有这么多水题,连续三道裸的最小生成树了。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;struct node{ int a, b, num; bool operator < ( const node& A) const { return num < A.num; }}edge[4100000];int N, e, set[2100], mp[510][510 阅读全文

posted @ 2012-07-12 10:09 more think, more gains 阅读(160) 评论(0) 推荐(0) 编辑

poj 2485 最小生成树

摘要: 算法:又是裸得最小生成树。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;struct node{ int a, b, num; bool operator < ( const node& A) const { return num < A.num; }}edge[4100000];int N, e, set[2100], mp[510][510];int find( in 阅读全文

posted @ 2012-07-12 10:02 more think, more gains 阅读(150) 评论(0) 推荐(0) 编辑

poj 1789 最小生成树

摘要: 1A,在POJ上好久没有1A了。。算法:裸的最小生成树,关键时认真读懂题意。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;struct node{ int a, b, num; bool operator < ( const node& A) const { return num < A.num; }}edge[4100000];char truck[2100][10]; 阅读全文

posted @ 2012-07-12 09:33 more think, more gains 阅读(142) 评论(0) 推荐(0) 编辑

POJ 2240 最长路 枚举

摘要: 题意:问给你一些货币兑换利率,利用这些汇率能否实现其原有货币增直。算法:1.肯定是个回路,不是回路输出No,而且这个回路是最长的,可以用SPFA求最长路,并判断是否构成回路。2.问题是不知到哪个是源点,也就是所有点得都有可能是源点,枚举所有点为源点,求N次SPFA(N<=30),构造一个货币初始直,如1.View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<map>#include<iostream>#include<string&g 阅读全文

posted @ 2012-07-12 09:03 more think, more gains 阅读(158) 评论(0) 推荐(0) 编辑

poj 1125 FLoyd

摘要: 题意:让你找一个点,从这个点向其它点传递信息所要的时间最短。输出这个点得编号,和最晚收到信息的人所需时间。算法:1.Dijkstra算法一次只能求单源最短路径,而FLoyd算法则可以求出每对顶点得最短路径,求一次则可。2.枚举每个点到各点的最大直,比较各点的最大直就可以得出答案。这个最大最大直就是最晚收到信息所需时间。View Code #include<stdlib.h>#include<string.h>#include<stdio.h>int mp[210][210];int N;const int inf = 0x7f7f7f7f;void Floy 阅读全文

posted @ 2012-07-12 08:08 more think, more gains 阅读(171) 评论(0) 推荐(0) 编辑

导航