随笔分类 -  模板

KeyWords Search(AC automation)
摘要:#include <cstdio> #include <cstring> using namespace std; const int num_char=26; struct TrieNode { TrieNode *branch[num_char]; TrieNode *fail; int count;//if this is the last node of the word TrieNode() { fail=NULL; count=0; memset(branch,NULL,sizeof(bra... 阅读全文
posted @ 2012-10-24 18:44 MicZ 阅读(197) 评论(0) 推荐(0)
HOJ 1225 Suptermarket(并查集)
摘要:题意:先给出商品个数n,然后对于每一个商品ai{pa,da},pa代表这个商品的利润,da代表这个商品必须在第d天之前售出. 每天只能卖出一个商品问如何安排卖的顺序,使得利润最大.输出最大利润分析:根据贪心的策略,按利润排序,利润最大的放在最前面.按ddl分集合ddl=1的集合,只能在0~1的时间卖.ddl!=1的集合,除了在ddl那天卖,还能在ddl之前的某一天卖,所以将ddl的商品,做成ddl-1的商品的子树.#include <iostream> //按deadline进行分集合 #include <cstdio> #include <memory.h> 阅读全文
posted @ 2012-10-21 15:53 MicZ 阅读(341) 评论(0) 推荐(0)
HOJ 1056 Machine Schedule (二分图匹配,匈牙利算法)
摘要:题意:给k个任务,每一个任务都能被Computer A的x_mode或Computer B的y_mode处理。mode的转换需要重启。问如何安排任务的处理顺序,可以使得重启的次数最少。分析:二分图匹配。将每一个任务看成一条边,端点分别是Computer A的x_mode和Computer B的y_mode。求最小覆盖,即用最少的点数,使得每一条边至少都有一个点与它相连。根据最小覆盖=最大匹配。求该二分图的最大匹配即可。使用匈牙利算法。代码如下:#include <iostream> #include <cstdio> #include <memory.h> 阅读全文
posted @ 2012-10-19 08:49 MicZ 阅读(159) 评论(0) 推荐(0)
线段树基本应用——区间最值查询
摘要:感觉对线段树快有阴影了。。还是先从最简单的开始吧。关键是理解原理。求区间最小值:题目:2 //testcases5 3 //n:数组元素个数,m:查询次数78 1 22 12 3 //输入数组,每个数最大值不超过10^51 2 //查询从l到r上的最小值3 54 4#include <cstdio> #include <algorithm> #define lson l , m , rt << 1 #define rson m + 1 , r , rt << 1 | 1 using namespace std; const int maxn = 阅读全文
posted @ 2012-10-06 09:43 MicZ 阅读(223) 评论(0) 推荐(0)
HOJ 1811 Freckles (Prim 最小生成树)
摘要:题意:平面上有n个点,并给出n个点的坐标。现在要用线把这些点全部连起来。问如何连使得线的总长度最短。分析:是一道裸的最小生成树问题。用Prim算法解决,贴到这儿当模板了。#include <iostream> #include <cstdio> #include <memory.h> #include <cmath> #define N 105 #define INF 0xfffffff using namespace std; struct Point { double x,y; } points[N]; double map[N][N]; b 阅读全文
posted @ 2012-10-01 10:36 MicZ 阅读(158) 评论(0) 推荐(0)