
数据结构
文章平均质量分 81
ahfywff
这个作者很懒,什么都没留下…
展开
-
POJ 3264 Balanced Lineup [RMQ]
求区间最大值与最小值之差。#include #include #include #include #include using namespace std;const int maxn = 50010;int n, q, a, b;int minh[maxn][16]; // minh[i][j]: h[i]~h[i+(1<<j)-1]的最小值 int maxh[maxn原创 2012-05-23 21:45:28 · 404 阅读 · 0 评论 -
HDU 4069 Squiggly Sudoku【Dancing Links精确覆盖】
跟普通的数独有一点点不同,先预处理一下再用Dancing Links进行精确覆盖即可。#include #include #include #include using namespace std;const int maxn = 9*9*9*9*9*4 + 10;const int oo = 1 << 30;const int maxrow = 9*9*9 + 10;co原创 2012-09-04 08:26:58 · 1112 阅读 · 0 评论 -
HDU 4262 Juggler(线段树)
2012 ACM/ICPC Asia Regional Online Warmup 1006题#include #include #include #include #include using namespace std;const int maxn = 100010;int sum[maxn<<2];int pos[maxn];int n;void bui原创 2012-08-25 17:20:12 · 1000 阅读 · 0 评论 -
HDU 3498 whosyourdaddy【Dancing Links重复覆盖】
有n个单位的敌人,对某个敌人进行攻击时该敌人以及与其直接相邻的敌人都会被消灭。问消灭所有敌人所需的最少攻击次数。重复覆盖问题。我把此题贴出来是想说剪枝优化很有必要,一个小细节就能决定是TLE还是AC。#include #include #include #include #include using namespace std;const int maxn = 60*60原创 2012-09-04 09:59:02 · 725 阅读 · 0 评论 -
HDU 3401 Trade【单调队列+dp】
题意:已知股票每天的买入和卖出价格、买入上限和卖出上限以及最多能持有的股票数,问n天后的最大收益是多少。#include #include #include #include #include using namespace std;const int oo = 1 << 30;const int maxn = 2010;int tcase;int t, maxp,原创 2012-08-27 16:49:36 · 1159 阅读 · 0 评论 -
HDU 3971. Play With Sequence【线段树+排序】
http://acm.hdu.edu.cn/showproblem.php?pid=3971题意:对有n(0=l且=l且解法:首先可以想到线段树,线段树的每个节点存当前区间的最大值和最小值,当然还有延迟标记。但是,如果就只是这样做,还是会TLE。由于每次更新是将>=l且#include #include #include #include #include using na原创 2012-09-26 00:13:42 · 1574 阅读 · 0 评论 -
HDU 4286 Data Handler【Splay Tree】【2012年天津网络赛1009】
我用伸展树过的这题,一直在TLE和RE之间徘徊。。。以下代码用C++交可以AC,G++会RE的。#include #include #include #include #include #pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int maxn = 100原创 2012-09-09 17:51:21 · 1892 阅读 · 0 评论 -
POJ 3481 Double Queue【SBT】
http://poj.org/problem?id=3481该SBT模板只实现了一些简单的操作,我会不断完善其它功能。#include #include #include #include #include using namespace std;const int maxn = 100010;struct Node { int key, val;原创 2012-09-27 23:50:28 · 1092 阅读 · 0 评论 -
ZOJ 3018 Population【二维线段树四分动态建树】
Population Time Limit: 10 Seconds Memory Limit: 32768 KB It is always exciting to see people settling in a new continent. As the head of the population management office, you are s原创 2012-09-13 23:37:05 · 1895 阅读 · 1 评论 -
SPOJ 3261. Race Against Time(RACETIME) 【线段树套SBT】
http://www.spoj.pl/problems/RACETIME/题意:1、修改某个数;2、求区间内小于等于某个数的数有多少个。#include #include #include #include #include using namespace std;const int maxn = 100010;struct Node { int key,原创 2012-10-04 22:14:47 · 1752 阅读 · 0 评论 -
POJ 1509 Glass Beads【后缀自动机、最小表示法】
此题为最简单的后缀自动机的应用。#include #include #include #include #include using namespace std;const int maxn = 10010;struct SamNode { int ch[26]; int par, len; void Init() { par =原创 2012-10-07 17:13:32 · 2465 阅读 · 1 评论 -
SPOJ 375. Query on a tree【树链剖分】
http://www.spoj.pl/problems/QTREE/给一颗树,每条边有一个权值。有两种操作:1、修改某条边的值;2、询问a、b两点路径上边权的最大值。树链剖分。#include #include #include #include #include #include using namespace std;const int maxn = 10010;原创 2012-09-18 21:00:39 · 1711 阅读 · 0 评论 -
POJ 1084 Square Destroyer【Dancing Links重复覆盖】
Square DestroyerTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2695 Accepted: 1101DescriptionThe left figure below shows a complete 3*3 grid made with原创 2012-09-04 14:27:39 · 2408 阅读 · 0 评论 -
HDU 2295 Radar【二分+Dancing Links重复覆盖】
重复覆盖不同于精确覆盖,要求是在0/1矩阵中选择最少的行使每一列至少有一个1。进行重复覆盖时要使用估价函数来剪枝。这题二分雷达半径,找到能将所有城市覆盖的最小半径即可。#include #include #include #include #include using namespace std;const int maxn = 50*50 + 10;const i原创 2012-09-04 08:35:12 · 895 阅读 · 0 评论 -
POJ 2452 Sticks Problem [RMQ+二分]
/*题意:给你一组数a[n],求满足a[i] < a[k] < a[j] (i <= k <= j)的最大的j-i。解法:RMQ + 二分。枚举i,利用二分求出a[i]右边第一个小于a[i]的数的位置k,再求出[i, k]中最大值的位置j,若a[j] > a[i],则更新结果。*/#include #include #include #include #include u原创 2012-05-24 19:11:00 · 1821 阅读 · 0 评论 -
POJ 2019 Cornfields [二维RMQ]
二维RMQ。求一个矩阵的子矩阵各元素的最大值与最小值之差。用int会超内存,改用short。#include #include #include #include #include using namespace std;const int maxn = 255;int n, b, k;short dpmin[maxn][maxn][10][10];short dpm原创 2012-05-24 12:24:40 · 1170 阅读 · 0 评论 -
POJ 1330 Nearest Common Ancestors [LCA+RMQ]
LCA的入门题,我用的是ST在线算法和Tarjan离线算法。ST:#include #include #include #include #include #include using namespace std;const int maxn = 10010;int t, n, cnt;vector son[maxn];int parent[maxn];bool vi原创 2012-05-25 21:38:38 · 834 阅读 · 1 评论 -
POJ 1986 Distance Queries [LCA]
#include #include #include #include using namespace std;const int maxn = 40010;const int maxk = 10010;int n, m, k;int cnt1, cnt2;int head1[maxn], head2[maxn];int set[maxn], an[maxn];int d原创 2012-05-26 16:28:01 · 553 阅读 · 0 评论 -
HDU 2874 Connections between cities [LCA]
题目给出的图不一定连通,可以虚拟一个根节点。查询时,若LCA(u, v)为根节点,则表示u,v不相连;否则,求出最短距离。#include #include #include #include #include #include using namespace std;const int maxn = 10010;int n, m, c, cnt;int e[maxn<<1]原创 2012-05-26 13:39:13 · 564 阅读 · 0 评论 -
POJ 1470 Closest Common Ancestors [LCA+RMQ]
这题的输入有点恶心,OLE很多次才过。。。ST:#include #include #include #include #include #include using namespace std;const int maxn = 10010;int n, q, cnt;vector son[maxn];int parent[maxn];bool vis[maxn];原创 2012-05-25 23:42:37 · 559 阅读 · 0 评论 -
HDU 4339 Query(线段树)
Problem DescriptionYou are given two strings s1[0..l1], s2[0..l2] and Q - number of queries.Your task is to answer next queries: 1) 1 a i c - you should set i-th character in a-th string to c原创 2012-08-03 15:39:48 · 698 阅读 · 0 评论 -
HDU 4313 Matrix (贪心+并查集)
题意:给你一个有n(2思路:我最开始想到的是:1、将边按权值由小到大排序。2、计算每条边连接的两个子树中分别有多少个机器人。3、然后,枚举每条边,如果该条边所连接的两个子树中都有机器人,则将该条边删除。4、重复步骤2和步骤3,直到枚举完所有的边。5、所删除的边的权值之和就是要求的结果。但是,这样做时间复杂度太高,主要是第2步花了太多的时间。后来,发现,完全可以反过来做,原创 2012-07-27 19:45:09 · 1002 阅读 · 0 评论 -
HDU 4315 Digital root(线段树)
很不错的线段树题。#include #include #include #include using namespace std;const int maxn = 100010;int tcase, n, q;int a[maxn];/*ldr: 从区间左端点开始的前n项和的数字根的二进制表示 rdr: 从区间右端点开始的后n项和的数字根的二进制表示 idr: 区间内原创 2012-08-14 16:17:44 · 750 阅读 · 0 评论 -
HDU 4358 Boring counting(线段树)
用C++交会栈溢出,而G++不会。更新和查询我用的是线段树,1500+ms,用树状数组应该会快一些。将树形结构转换成线性结构后,等价于求指定区间内恰好出现k次的数有多少个。#include #include #include #include #include #include using namespace std;const int maxn = 100010原创 2012-08-15 00:40:18 · 2034 阅读 · 1 评论 -
HDU 4325 Flowers(线段树)
线段树的区间更新和单点查询。需要注意的是要把区间端点和查询的点都先读入并离散化。#include #include #include #include #include #include #include using namespace std;const int maxn = 100100;int tcase, n, m;int sum[maxn<<2], add[m原创 2012-08-01 20:21:05 · 997 阅读 · 4 评论 -
HDU 4348. To the Moon【可持久化树状数组】
http://acm.hdu.edu.cn/showproblem.php?pid=4348#include #include #include #include #include #include using namespace std;const int maxn = 100010;int n, m;struct Node { long long d,原创 2012-09-25 20:38:02 · 3509 阅读 · 0 评论