上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 17 下一页

2011年8月17日

RMQ与LCA

摘要: RMQ英文是Range Maximum(Minimum) Query,是用来求取某个区间的最大值最小值,通常用在查询次数比较大的区间最值问题中。RMQ的原理是动态规划,利用了倍增的思想。我们用A[1...N]表示一组数,[Li,Ri]表示题目涉及到的查询区间。设F[i,j]表示从A[i]到A[i + (2^j) - 1]这个范围的最大值,也就是以A[i]为起点的连续2^j个数的最大值。由于元素个数是2^j,可以均分为两部分,每部分有2^j-1个数。整个区间的最大值肯定是前半部分的最大值和后半部分最大值的较大者,满足动态规划的最优子结构。则动归方程为:f[i, j] = max(f[i, j-. 阅读全文

posted @ 2011-08-17 21:27 _Clarence 阅读(235) 评论(0) 推荐(0) 编辑

ACM PKU 2155 Matrix

摘要: 题目描述: http://poj.org/problem?id=2155树状数组第一题,很诡异的思想; 1 #include<iostream> 2 #include<cstdio> 3 #include<string.h> 4 //BIT 5 //2155 6 using namespace std; 7 const int maxn=1009; 8 int n,Q; 9 int c[maxn][maxn];10 int lowbit(int a) //其实还有这么一个公式可以求x的lowbit:x&(x^(x–1)); 11 {12 return 阅读全文

posted @ 2011-08-17 19:08 _Clarence 阅读(173) 评论(0) 推荐(0) 编辑

2011年8月16日

ACM PKU 3264 Balanced Lineup

摘要: 题目描述:http://poj.org/problem?id=3264这是我做的第一道线段树题,超时两次,最后过得也很悲剧,差点没有把我笑死,poj好几页的waiting,我还以为服务器挂了。等了好久,结果一翻我交的题,蓝色的Ac,我当时那个喜呀,哈哈...方法一:线段树初级题,水过; 1 #include <iostream> 2 #include <string> 3 #include <cstring> 4 #include <cstdio> 5 #include <algorithm> 6 const int MAXN=500 阅读全文

posted @ 2011-08-16 10:16 _Clarence 阅读(119) 评论(0) 推荐(0) 编辑

2011年8月15日

ACM PKU 2240 Arbitrage

摘要: 题目大意:http://poj.org/problem?id=2240一个人想利用兑换关系赚钱,给你几种兑换关系,要你求出这个人最开始有一美元,通过一连串的兑换看看最终是不是能赚到钱;问题转化为:先构图,单向图;然后求多源最短路径,只要G[i][i]>1.0的话就是赚钱了,意思就是给你一块钱,走一圈之后的钱比1块钱多就是赚钱了;找一个回路的最大值;这里Floyd求的肯定是最大值了,还有要注意的是double G[][],rate浮点型的; 1 #include <iostream> 2 #include <stdio.h> 3 #include <strin 阅读全文

posted @ 2011-08-15 17:09 _Clarence 阅读(105) 评论(0) 推荐(0) 编辑

ACM PKU 1062 昂贵的聘礼

摘要: 题目描述:http://poj.org/problem?id=1062所有给的测试数据都过了,就是一直wa,百思不得其解啊! 1 #include <iostream> 2 #include <string.h> 3 #include <stdio.h> 4 const int inf=1000000; 5 const int maxn=105; 6 using namespace std; 7 8 struct node 9 { 10 int weight,rank; 11 } point[maxn]; 12 13 int M,N; 14 int G[ma 阅读全文

posted @ 2011-08-15 09:52 _Clarence 阅读(142) 评论(0) 推荐(0) 编辑

2011年8月13日

ACM PKU 1192 最优连通子集

摘要: 题目描述:http://poj.org/problem?id=1192说实话,这道题我看了半天恁是没有看懂什么意思,最后看人家代码写了一个深搜,还是看代码容易理解一点,也不知道是中文的说明有问题还是我的理解能力有问题,呵呵不管了,看代码吧! 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <algorithm> 5 #include <cmath> 6 #include <vector> 7 using namespac 阅读全文

posted @ 2011-08-13 20:58 _Clarence 阅读(118) 评论(0) 推荐(0) 编辑

2011年8月12日

ACM PKU 1273 Drainage Ditches

摘要: 题目描述: http://poj.org/problem?id=1273第一道最大网络流算法题,也是跟着老师写的 1 #include <iostream> 2 using namespace std; 3 #define MAX 100000000 4 #define MAXN 205 5 6 int pre[MAXN+10],prem[MAXN+10]; 7 int ecnt,box[MAXN]; 8 9 struct node10 {11 int to,next,w;12 }edge[MAXN*2];13 14 void make_map(int from,int to,in 阅读全文

posted @ 2011-08-12 19:05 _Clarence 阅读(134) 评论(0) 推荐(0) 编辑

ACM PKU 1325 Machine Schedule http://poj.org/problem?id=1325

摘要: 第一个二分图的题目,匈牙利算法,跟着老师做完了,展示老师的代码,威武,哈哈 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 const int maxn=105; 6 7 bool flag[maxn]; 8 int match[maxn]; 9 int map[maxn][maxn];10 11 int N,M,K;12 13 bool xyy(int s)14 {15 for(int i=0; i<M; i++)16 阅读全文

posted @ 2011-08-12 19:03 _Clarence 阅读(134) 评论(0) 推荐(0) 编辑

ACM PKU 3723 Conscription http://poj.org/problem?id=3723

摘要: 一道最大生成树的题,重载一下"<"号就行,因为会存在森林的情况,所以prim算法不好做,kruskal是是解决这道题的神器; 1 #include <stdio.h> 2 #include <iostream> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 const int maxp = 10005; 8 9 const int maxe = 50005;10 11 int N,M,R;12 13 int pre[maxp* 阅读全文

posted @ 2011-08-12 10:45 _Clarence 阅读(203) 评论(0) 推荐(0) 编辑

2011年8月11日

ACM PKU 1251 Jungle Roads http://poj.org/problem?id=1251

摘要: 最小生成树水题,用prim ,注意一下图书无向图; 1 #include <iostream> 2 #include <string.h> 3 #include <stdio.h> 4 using namespace std; 5 6 const int maxn=27; 7 8 const int inf=0x7fffffff; 9 10 int village;11 12 int lowcost[maxn],adjvex[maxn];13 14 int G[maxn][maxn];15 16 int MinEdge()17 {18 int index = 阅读全文

posted @ 2011-08-11 16:52 _Clarence 阅读(213) 评论(0) 推荐(0) 编辑

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 17 下一页

导航