摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1754线段树入门题:求区间段的最大值#include "iostream"#include "stdio.h"using namespace std;const int MAX = 200001;int big;struct node{ int r, l, max;}tree[MAX * 3];void Create(int t, int left, int right) //建树{ tree[t].l = left; tree[t].r = right; tree[t 阅读全文
posted @ 2011-08-02 18:18 Firecoder 阅读(127) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1129四色定理#include "stdio.h"#include "iostream"#include "cstring"using namespace std;bool g[27][27];int color[27];bool dfs(int nColor, int now, int n) //nColor:所用颜色总数;now:当前待填颜色的物品的编号{ if(now > n) return true; for(int i = 1; i <= nColor; i+ 阅读全文
posted @ 2011-08-02 16:27 Firecoder 阅读(125) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1164提交的时候正遇oj挂了,害我白白错了几次,却不知情。。。#include "iostream"#include "stdio.h"#include "string.h"using namespace std;struct room{ bool vis; int val;}castle[51][51];int area;void dfs(int x, int y){ if(!castle[x][y].vis) { area++; castle[x][y].vis = true; 阅读全文
posted @ 2011-08-02 16:24 Firecoder 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 两道题都是求最小生成树的最长边。poj 2395 Out of Hay http://poj.org/problem?id=2395kruskal实现:#include "stdio.h"#include "string.h"#include "algorithm"#include "iostream"using namespace std;const int INF = 1e9, MAX = 2001;int fa[MAX];struct edge{ int s, e, val;};edge edges[1000 阅读全文
posted @ 2011-08-02 11:14 Firecoder 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 第一次写SPFA,小激动一下。。。http://poj.org/problem?id=1511#include "iostream"#include "stdio.h"#include "queue"#include "string.h"using namespace std;const int MAX = 1000010;const int INF = 1e9;struct edge{ int s, e; int val; int nextedge;};struct edge edges1[MAX], edges 阅读全文
posted @ 2011-08-02 09:58 Firecoder 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 最短路径之SPFA算法 求最短路径的算法有许多种,除了排序外,恐怕是OI界中解决同一类问题算法最多的了。最熟悉的无疑是Dijkstra,接着是Bellman-Ford,它们都可以求出由一个源点向其他各点的最短路径;如果我们想要求出每一对顶点之间的最短路径的话,还可以用Floyd-Warshall。SPFA是这篇日志要写的一种算法,它的性能非常好,代码实现也并不复杂。特别是当图的规模大,用邻接矩阵存不下的时候,用SPFA则可以很方便地面对临接表。每个人都写过广搜,SPFA的实现和广搜非常相似。 如何求得最短路径的长度值? 首先说明,SPFA是一种单源最短路径算法,所以以下所说的“某点的最短路径长 阅读全文
posted @ 2011-08-01 14:48 Firecoder 阅读(306) 评论(0) 推荐(0) 编辑