08 2011 档案
摘要:poj 2186 Popular Cows强连通分量 tarjanhttp://poj.org/problem?id=2186#include <iostream>#include "stdio.h"#include "string.h"using namespace std;struct node{ int v, next;}edge[50000];const int MAXV = 10001;int adj[MAXV], lp, low[MAXV], dfn[MAXV], out[MAXV], belong[MAXV], stack[MA
阅读全文
摘要:http://poj.org/problem?id=3714#include "stdio.h"#include "cmath"#include "iostream"#include "algorithm"using namespace std;struct point{ long long x, y; bool flag;};point p[200003];point tp[200003];bool cmp_x(const point & a, const point & b) { return
阅读全文
摘要:hdu 1007 Quoit Design (最近点对)http://acm.hdu.edu.cn/showproblem.php?pid=1007“最近点对”的经典入门题所用到的思想和“归并排序”类似, 分治再合并。#include "stdio.h"#include "cmath"#include "iostream"#include "algorithm"using namespace std;struct point {double x, y;};point p[100003];point tp[10000
阅读全文
摘要:文章来源: http://hi.baidu.com/studyrush/blog/item/08ba35012c755383d43f7ce2.html最短路问题此类问题类型不多,变形较少POJ 2449 Remmarguts' Date(中等)http://acm.pku.edu.cn/JudgeOnline/problem?id=2449题意:经典问题:K短路解法:dijkstra+A*(rec),方法很多相关:http://acm.pku.edu.cn/JudgeOnline/showcontest?contest_id=1144该题亦放在搜索推荐题中POJ 3013 - Big
阅读全文
摘要:文章来源:http://hi.baidu.com/novosbirsk/blog/item/723a9727a9ab8804918f9dca.html其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中。之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的算法,在很多领域有着重要的用途(例如本人的专业,GIS)。以后若有机会,我会补充、完善这个列表。计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板很重要,模板必须高度可靠。3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面大部分是模板。如果代
阅读全文
摘要:文章来源:http://www.byvoid.com/blog/scc-tarjan/ (BYVoid 原创作品,转载请注明。)[有向图强连通分量]在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(strongly connected)。如果有向图G的每两个顶点都强连通,称G是一个强连通图。非强连通图有向图的极大强连通子图,称为强连通分量(strongly connected components)。下图中,子图{1,2,3,4}为一个强连通分量,因为顶点1,2,3,4两两可达。{5},{6}也分别是两个强连通分量。直接根据定义,用双向遍历取交集的方法求强连通分量,时间复杂度为O
阅读全文
摘要:经典的欧拉回路题http://poj.org/problem?id=1041欧拉回路:每条边经过一次且仅一次的称为欧拉回路(euler cycle, euler circuit)。存在欧拉回路的充要条件:每个点的度数都是偶数, 且图连通。#include "iostream"#include "stdio.h"#include "string.h"#include "algorithm"using namespace std;int G[50][2000]; //G[点][边] = 点,这样是为了能方便让边lexi
阅读全文
摘要:http://poj.org/problem?id=3267#include "stdio.h"#include "iostream"#include "string.h"using namespace std;char dict[610][30]; //the cows' dictionarychar seq[310]; //the received messageint dp[310];int min(int a, int b){ return a < b ? a : b;}int main(){ int n, L,
阅读全文
摘要: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
阅读全文
摘要: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+
阅读全文
摘要: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;
阅读全文
摘要:两道题都是求最小生成树的最长边。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
阅读全文
摘要:第一次写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
阅读全文
摘要:最短路径之SPFA算法 求最短路径的算法有许多种,除了排序外,恐怕是OI界中解决同一类问题算法最多的了。最熟悉的无疑是Dijkstra,接着是Bellman-Ford,它们都可以求出由一个源点向其他各点的最短路径;如果我们想要求出每一对顶点之间的最短路径的话,还可以用Floyd-Warshall。SPFA是这篇日志要写的一种算法,它的性能非常好,代码实现也并不复杂。特别是当图的规模大,用邻接矩阵存不下的时候,用SPFA则可以很方便地面对临接表。每个人都写过广搜,SPFA的实现和广搜非常相似。 如何求得最短路径的长度值? 首先说明,SPFA是一种单源最短路径算法,所以以下所说的“某点的最短路径长
阅读全文