- 博客(48)
- 资源 (9)
- 收藏
- 关注
原创 HDU 1214 圆桌会议
刚开始觉得题目有问题。后来发现是相邻的才能交换。 一个环形的圈怎样用最少次数把它从顺时针变成逆时针(只能相邻位置交换位置) 一个环形,最优结果是把这个环分成 相差 最少的2部分,这2部分按照直线来求出结果再求和 直线如果把1234 换成4321 是冒泡的次数。。首先4123(3)+4312(2)+4321(1)=6 重点是把n看成两个 n/2 ,然后求出进行反序(冒泡)的次数。n
2013-01-29 11:01:41
994
原创 HDU 1273 漫步校园 orz
乱搞题,n-1减去起点,把剩下的点分成尽可能相等的两部分1、2(为了得到尽可能大的答案) 对于1内部来讲,显然总能保证“新鲜”,在新鲜1后,不难看出2的每个点都对应着一个“新鲜” #include using namespace std; int main() { int n; while(scanf("%d",&n),n) printf("%d\n",(n-1)>>1); ret
2013-01-29 10:44:25
826
原创 HDU 1234 水
用了string,如果不用会麻烦很多。 #include #include using namespace std; int main() { int t; cin >> t; while(t--) { int n; cin >> n; string id, start, end; cin >> id >> start >> end; string idstar
2013-01-29 10:34:37
1343
原创 HDU 1428 漫步校园 SPFA + DFS记忆搜索
类似上题。 #include #include #define inf 0x7fffffff struct { int v, pow, next; }edge[52*52*4]; int n = 0, map[52][52], head[52*52], dis[52*52], dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}}; __int64 c
2013-01-29 10:20:08
805
原创 HDU 1142 SPFA + DFS记忆搜索 学习了!!
走AB这条路的前提是: B到home的最短路比A到home的最短路要短,求满足这个要求的office到home的路有多少条 SPFA:参考http://sgeteternal.iteye.com/blog/1148891 spfa比dijkstra极大程度减少不必要的松弛操作。故而比dij快。 #include #include #include #include #include
2013-01-28 17:04:48
658
原创 HDU 2546 01背包,可达性问题 hash思想
类似01背包。用hs[n]= 1表示是否可达。 可以证明如果饭卡的钱大于5的话,必然会点价格最高的菜。 所以问题转化为求m-5范围内点菜。越接近越好。这就是01背包。。 #include using namespace std; const int N = 1105; int hs[N]; int price[N]; int main() { int n, m; while(scanf
2013-01-28 15:32:33
1102
原创 HDU 2544 dijkstra
水。。 #include using namespace std; const int N = 105; const int INF = 0x1fffffff; int map[N][N]; int D[N]; int flag[N]; int n, m; void init() { for(int i = 0; i < N; i++) for(int j = 0; j < N; j++
2013-01-28 10:34:48
589
原创 HDU 2476 字符串a转化为字符串b需要几次操作 结合编辑距离
与编辑距离思想类似,但是编辑距离每次只能增删改。还涉及到字符串的对齐问题。http://blog.csdn.net/vsooda/article/details/8313172 而本题每次修改就修改一个区间。自然地,使用dp[i][j]表示从i 到 j 所需要的修改次数的上界。 初始化dp[i][j]为dp[i+1][j] + 1 如果s2[i] == s2[k] dp[i][j] =
2013-01-28 10:09:47
1844
原创 HDU 1690 floyd
#include #include #include using namespace std; const long long INF = 1e18; const int VN = 105; int n; int m; long long d[VN][VN]; long long X[VN]; long long L1,L2,L3,L4; long long C1,C2,C3,C4; i
2013-01-27 20:49:35
1022
原创 HDU 1385 带点权值Floyd+路径记录
注意记录后缀的方法。。 #include #include int a[50][50]; int c[50][50]; int b[50]; int find(int beg,int end) { while(c[beg][end]!=end) { printf("-->%d",c[beg][end]); beg=c[beg][end]; } printf("-->%d\n"
2013-01-27 19:48:29
970
原创 HDU 1874 最短路径
有重边,wa了半天。#include using namespace std; #define N 205 int n, m; int map[N][N]; int sea[N]; int D[N]; int flag[N]; void floyd() { for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) for(int k
2013-01-27 19:08:31
583
原创 HDU 3665 dijkstra floyd
分别用dijkstra 和floyd做了。。奇怪的是,时间都是15MS #include using namespace std; #define N 12 int n, m; int map[N][N]; int sea[N]; int D[N]; int flag[N]; void floyd() { for(int i = 0; i < n; i++) for(int j = 0;
2013-01-26 23:20:37
659
原创 HDU 1869 floyd 求两点间的最短距离
求两点之间的最短距离 //memset(map, 0x1ffffff, sizeof(map));//错误的初始化方式 正确使用memset的方式是,初始指定的是8位的数值。比如说memset(map, 0x3f, sizeof(map)); 则map如果是int类型,则被初始化为4个3f 即 0x3f3f3f3f #include using namespace std; #define
2013-01-26 22:18:15
919
原创 HDU 3007 最小圆覆盖
题意:给出平面上的一些点,要求用一个最小的圆,把所有的点包围起来。 最小覆盖圆, 增量法 假设圆O是前i-1个点得最小覆盖圆,加入第i个点,如果在圆内或边上则什么也不做。否,新得到的最小覆盖圆肯定经过第i个点。 然后以第i个点为基础(半径为0),重复以上过程依次加入第j个点,若第j个点在圆外,则最小覆盖圆必经过第j个点。 重复以上步骤(因为最多需要三个点来确定这个最小覆盖圆,所以重复三次)
2013-01-25 21:12:48
4166
原创 HDU 1370 打表 || 中国剩余定理
题意:有3个循环周期,周期天数分别为23、28、33。对于某一年,已知某年这3个周期的某一峰值分别是当年的第p、e、i天,问从第d天开始到最近一个满足3个周期都达到峰值的日期还有多少天。 数据比较小,直接打表可过: # include int tab[40][40][40]; int cal(int num) { if (num <= 0) return num + 21252 ; r
2013-01-25 21:02:10
944
原创 HDU 1134 大数取模 使用大数模板
#include #include #include #include using namespace std; char str[1010]; int modd; #define MAXN 9999 #define MAXSIZE 10 #define DLEN 4 class BigNum { private: int a[1010]; //可以控制大数的位数 i
2013-01-25 20:35:44
4695
转载 c++ 大数类 大数模板
转自:http://blog.csdn.net/hackbuteer1/article/details/6595881 分别使用C++中的运算符重载的方法来实现大数之间的数学运算,包括加法、减法、乘法、除法、n次方、取模、大小比较、赋值以及输入流、输出流的重载。。 并且使用这个大数模板,顺利AC了HDOJ上的1134这个题目的Catalan数计数问题。。http://acm.
2013-01-25 20:23:36
23291
9
原创 HDU 1358 KMP运用 求某串中所有循环前缀串的长度和循环次数
解题思路: 这个题其实用的是next[]数组的性质来求周期、假设前K个元素匹配成功,则有str[1]=str[i-next[i] ],str[2]=str[i-next[i]+1]······str[i]=str[next[i]]。那么我们知道从str[0]到str[next[i]]是字符串的一个循环周期,即i-next[i]为重复的长度,那么长度为K的字符串中的循环次数为i/(i-next[i
2013-01-25 19:39:58
1738
原创 HDU 1496 等式求解 简单hash
没有判断同号,超时了半天。 #include using namespace std; #define N 2000010 #define M 1000010 int res[N]; int res2[N]; int t[101]; int main() { for(int i = 0; i <= 100; i++) { t[i] = i * i; } int a, b, c,
2013-01-25 19:02:56
638
原创 HDU 1423 最长上升公共子序列
参考:http://www.cnblogs.com/nuoyan2010/archive/2012/10/17/2728289.html #include #include using namespace std; const int N = 505; int num1[N],num2[N],f[N][N]; int main() { int t,n,m; scanf("%d",&t);
2013-01-25 17:15:15
3035
原创 HDU 1381 hash
主要思路:将出现的字符用nc进制的数来表示,保证其不会重复出现。。若有重复子字符串则这个数就相同,len-n+1 总的子字符串个数。。这个需要仔细观察。hash存储查找一遍重复的--最后就只剩下不重复的子字符串的个数了。 #include #include #define N 16000007 int hash[8000000],assi[27]; char str[N]; int a
2013-01-25 16:26:17
1370
原创 HDU 1753 大数 strchr
#include #include int a[1010],b[1010],sum[1010]; char str[1010]; int main() { int i,j,k,n,s,c; while(scanf("%s",str)==1) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(sum,0,sizeof(su
2013-01-18 16:44:15
590
原创 HDU 1316 大数
打表方法有点特别 对齐方法也不错。 #include #include #include #include #define M 105 char a[M+2], b[M+2]; char book[1000][M+2]; int cmp(char *s1, char *s2) { for(int i = 0; i <= M; i++) { if(i == M) { r
2013-01-18 15:51:17
1028
原创 HDU 3247 AC自动机 + 状态压缩dp
小HH:乳鸽的神题,状态很容易看出来,有50000*1024,很难保持,我用散列表超时了,用bitset刚好可以卡过,不过后来我想,只有尾结点才有效,中间的很多结点完全可以忽略,可以先用最短路吧各个尾结点之间的距离算出来,经过测试,不到50个点,马上就优化到50*1024了,本来9s多过的优化到了100多MS #include #include #include #include #in
2013-01-18 13:10:36
809
转载 树形dp 和 状态压缩dp
状态压缩动态规划 动态规划的状态有时候比较难,不容易表示出来,需要用一些编码技术,把状态压缩的用简单的方式表示出来。典型方式:当需要表示一个集合有哪些元素时,往往利用2进制用一个整数表示。 *:一般有个数据 n *:确定了为状态DP,那么第一步就是预处理,求出每行所有可能的状态了,cnt记录总的状态数,stk[]记录所有的可能状态。以炮兵阵地为例: int cnt, stk[MAX];
2013-01-16 21:57:45
794
原创 PKU 1185 炮兵阵地 经典状态压缩dp
思路:状态压缩DP。很经典的状态压缩DP。用int型来表示每行的状态(如果int型的二进制的第i位为1,则表示这一行的第i列有安装大炮)。这样的话由于最多有10列,故由计算可得最多有60种状态。DP部分:dp[r][i][k]表示第r行的状态为k,第r-1行的状态为i时候,前r行最多能够安装的大炮数量。 #include #define max(a,b) ((a)>(b)?(a):(b))
2013-01-16 21:55:57
760
原创 PKU 2778 HDU 2243 AC自动机 + 矩阵乘法
矩阵乘法:http://blog.csdn.net/vsooda/article/details/8510131 构造trie图,继而构造出初始矩阵,mat[i][j]表示i走到j有几种走法 ,这个矩阵自乘n次之后就表示i走到j走n步有几种走法 问你长度为N的串中不包含了模式串的串有几个 n属于1 ~ 2000000000看到这个数据范围我们就应该敏感的想到这是矩阵~ 最多100个结点,先
2013-01-16 18:32:01
794
原创 PKU 3233 经典矩阵乘法
S = A + A2 + A3 + … + Ak. 的一个很好的求法是 构造这样一个矩阵 A A 0 1 然后这个矩阵自乘K次即可,也就是矩阵套矩阵 #include #include const int MAX = 65; int n, k, m, tn, mod; struct Mat{ int mat[MAX][MAX]; Mat() { memset(mat,
2013-01-16 16:46:57
857
原创 HDU 3065 病毒侵袭持续中
目标串中各个模式串出现了几次 这就更简单了,都不用把out标记成false了 题目中的病毒都是大写字母这个条件应该怎么用? #include #include #include #include #include #include #include #include #include #include #include #include #include #incl
2013-01-16 15:59:24
588
原创 HDU 2896 病毒侵袭 AC自动机
这题的字母范围为128. 要注意的是,匹配之后不能将val[tmp] = 0; 因为下一个例子还要使用。 #include #include #include #include #include #include #include #include #include #include #include #include #include #include using
2013-01-16 15:39:20
531
原创 HDU 2222 AC自动机经典题目
应用模板,对模板有更深入的理解。 1. 当前结点的失败指针 等于 父节点的失败指针指向的结点的的同个字母儿子结点的指针 2. v = chd[ fail[u] ][i];这句为了别的结点计算败者指针提供便利。无其他作用。 3. work在结点之间的转移方式 #include #include #include #include #incl
2013-01-16 11:12:39
624
转载 HDU 2825 AC自动机模板
首先简要介绍一下AC自动机:Aho-Corasick automation,该算法在1975年产生于贝尔实验室,是著名的多模匹配算法之一。一个常见的例子就是给出n个单词,再给出一段包含m个字符的文章,让你找出有多少个单词在文章里出现过。要搞懂AC自动机,先得有模式树(字典树)Trie和KMP模式匹配算法的基础知识。AC自动机算法分为3步:构造一棵Trie树,构造失败指针和模式匹配过程。
2013-01-15 09:53:59
954
原创 PKU 3067 Japan 树状数组
求道路的交叉点数。 将道路按左边城市从大到小排序。如果相同则按右边从大到小排序。 这样就跟stars和cows一样了。 #include #include using namespace std; const int maxn = 1010; int c[maxn],result[maxn]; typedef struct { int e, s; } node; node nd[
2013-01-14 09:21:30
622
原创 PKU 2481 COWS 排序 + 树状数组
排好序后就跟stars那题一样了 一次遍历排序后的数组,由于比当前遍历元素strong的区间只可能存在于已经遍历过的元素中;所以我们可以放心大胆的直接对树状数组求和 然后向后更新树状数组中统治x的点上的值,因为那些位置都多了一个比 以他们为左端点的区间 强壮 的区间; #include #include using namespace std; const int maxn =
2013-01-13 11:00:18
607
原创 PKU 1195 二维树状数组
题目大意:给定n*n矩阵,和几种在线操作,包括对某一点(x,y)值修改,查询一个矩形(l, b, r, t)的元素和。 二维的树状数组,直接把Update()和Getsum()改为二维即可#include using namespace std; const int maxn = 1100; int tree[maxn][maxn]; int Lowbit(int x) { re
2013-01-12 22:44:59
678
原创 PKU 2352 Stars 求比较小的数字个数
题目意思就是求每个星星左下方的星星的个数,由于y轴已经排序好了,我们可以直接用按x轴建立一维树状数组,然后求相当于它前面比它小的个数,模板直接一套就搞定了~~ #include using namespace std; const int MAX = 32000 + 10; int c[MAX], level[MAX]; int Lowbit(int x) { return
2013-01-11 21:37:19
734
原创 PKU 2299 求解逆序数(使用归并或者树状数组) 树状数组及入门知识
归并ac代码为: #include #include using namespace std; #define MAX 500005 int a[MAX], t[MAX]; __int64 cnt; void Merge(int l, int mid, int r) { int i = l, j = mid + 1, k = 0; while(i <= mid && j <= r
2013-01-11 15:41:03
715
原创 HDU 1247 trie 一个单词是否是两个单词的连接
#include using namespace std; char list[50001][26]; const int kind = 26; int cnt = 0; struct Treenode { bool flag; Treenode *next[kind]; Treenode() { flag = false; f
2013-01-10 22:09:08
606
原创 HDU 1671 静态trie(字典树)
#include #include using namespace std; const int MAXNODE = 500000; const int BRANCH = 10; int tree[MAXNODE][BRANCH]; int SIZE; //结点下标 bool key[MAXNODE];//是否是某个单词 bool Insert(char *str) { int node
2013-01-10 19:56:30
1082
原创 HDU 1686 统计子串的个数 kmp 调了半天
题意不解释了。 第一版本代码:WA #include #include using namespace std; char s1[1000000+10], s2[10000+10]; void get_nextval(char* T, int nextval[]) { int i = 1, j = 0; nextval[1] = 0; while(i < T[
2013-01-10 11:02:53
938
1
OpenCV 2 Computer Vision Application Programming Cookbook 全
2012-06-01
线性规划与网络流题解
2012-09-26
计算机视觉:一种现代方法(第二版)清晰文字版(英文版)
2013-03-14
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人