
数据结构与算法
Davenny
O ever youthful,O ever weeping.
展开
-
堆模板
//维持最小堆//调整void down(int p){ int q=p*2; a=heap[p]; while(q<=hlength) { if(q<hlenth&&heap[q]>heap[q+1])//寻找当前子节点中较小的那个 { q++; } if(heap[q]>原创 2017-07-02 15:32:29 · 261 阅读 · 0 评论 -
拓扑排序:Ordering Tasks
DescriptionJohn has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The input will consist转载 2016-08-03 19:21:14 · 391 阅读 · 0 评论 -
栈:Parentheses Balance
SubmitStatus Description You are given a string consisting of parentheses () and []. A string of this type is said to be correct:(1) if it is the empty string(2) if A and B are correct, AB is correct原创 2016-08-03 16:10:46 · 269 阅读 · 0 评论 -
POJ2418:字典树:Hardwood Species(二叉搜索树)
DescriptionHardwoods are the botanical group of trees that have broad leaves, produce a fruit or nut, and generally go dormant in the winter. America’s temperate climates produce forests with hundred原创 2016-07-28 09:07:51 · 450 阅读 · 0 评论 -
单调栈:POJ2082:Terrible Sets
http://poj.org/problem?id=2082Language: Terrible Sets Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4355 Accepted: 2254 DescriptionLet N be the set of all natural numbers {0 ,原创 2016-07-25 14:29:41 · 253 阅读 · 0 评论 -
poj2728:最优比率生成树
题目大意: 在村庄之间修路,有水平距离和垂直距离,要求水平距离之和与垂直距离之和的比值最小;思路: r=sigma(val[i])/sigma(cost[i]); 可得式子:f(l)=[sigma(val[i])-l*sigma(cost[i])]*x[i]=d[i]*x[i]; x[i]为1或0,表示要和不要这条边; 有数学知识可得: 当r最大时d[i]为零;此直线为斜率为负数,截距为原创 2016-08-22 15:29:32 · 294 阅读 · 0 评论 -
出栈序列是否正确
[Submit][Status][Web Board] Description 整数1…N从小到大依次入栈,期间可以出栈。判别给定的整数序列是否正确的出栈序列。Input 包含多组测试数据,每组数据包含一行,每行一个整数为n(0#include <stack>#include <iostream>#include <cstring>#include <cstdio>using name原创 2016-10-04 09:51:16 · 698 阅读 · 0 评论 -
栈的应用:解析算术表达式
原博客:http://blog.youkuaiyun.com/zhangxiangDavaid/article/details/27176751类似于 1*2-3+4-(5-6)-2/4 的式子,我们称为算术表达式。下面我们利用栈这种数据结构来解析它,即用栈来辅助计算算术表达式。 首先我们得明确计算规则: 先左后右:从左算到右 先乘除,后加减 先括号内,后括号外 原理: 使用两个栈来存储读入的字符:转载 2016-10-04 09:36:58 · 536 阅读 · 0 评论 -
poj1639:最小度限制生成树
题目:http://poj.org/problem?id=1639 题目大意: 所有的车要去同一地点,而此地点对车子有一个最大容量K,所以车子在行驶的过程中,可以相互合并,求所有车子到达目的地的距离和的最小值;思路: 我们可以现将出目的地以外的车子建立最小生成树,然后从目的地向各子树连接最短边形成一棵树; 然后向子树中连接一条边,这样必定会形成一个环,那么就要把这个环中最大的那个边去掉,直到原创 2016-08-22 20:51:01 · 369 阅读 · 0 评论 -
hdu6133
Though being cruel and merciless in the battlefields, the total obedience to the command hierarchy makes message delivering between Stormtroopers quite inefficient, which finally caused the escape of L转载 2017-08-18 16:48:29 · 408 阅读 · 0 评论 -
HDU4417_树状数组加离线
Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory. Now the poor princess is in trouble again and Mario needs to save his lover. We regard the road to原创 2017-08-13 10:24:07 · 361 阅读 · 0 评论 -
单调队列
Description What a sunny day! Let’s go picnic and have barbecue! Today, all kids in “Sun Flower” kindergarten are prepared to have an excursion. Before kicking off, teacher Liu tells them to stand in转载 2016-07-06 20:59:52 · 465 阅读 · 2 评论 -
树状数组 模板:敌兵布阵
Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。 中央情报局要研转载 2016-07-06 21:03:34 · 299 阅读 · 0 评论 -
平衡二叉树模板
poj2418字典树#include <cstdio>#include <algorithm>#include <cstring>using namespace std;typedef struct AVLTree{ char name[31]; int cnt; struct AVLTree *pLeft; struct AVLTree *pRight;原创 2017-07-02 14:54:04 · 378 阅读 · 0 评论 -
Trie字典树模板
#include<iostream> #include<cstring> using namespace std; typedef struct Trie_node { int count; // 统计单词前缀出现的次数 struct Trie_node* next[26]; // 指向各个子树的指针 boo原创 2017-07-03 11:21:15 · 428 阅读 · 0 评论 -
Treap模板
#include<cstdio>#include <cstring>#include <cstdlib>#include <time.h>#include <iostream>using namespace std;struct Treap_Node{ Treap_Node *left,*right; int val,fix;};void Treap_Left_Ro原创 2017-07-02 21:19:02 · 319 阅读 · 0 评论 -
2002: [Hnoi2010]Bounce 弹飞绵羊
http://www.lydsy.com/JudgeOnline/problem.php?id=2002Description某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏。游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置设定初始弹力系数ki,当绵羊达到第i个装置时,它会往后弹ki步,达到第i+ki个装置,若不存在第i+原创 2017-07-15 10:45:12 · 325 阅读 · 0 评论 -
hdu 4366
http://acm.hdu.edu.cn/showproblem.php?pid=4366 SuccessorTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 4340 Accepted S原创 2017-07-15 16:45:45 · 423 阅读 · 0 评论 -
左偏树模板
解析链接:http://www.cnblogs.com/skywang12345/p/3638327.htmlstruct Tree{ int value; int dist; Tree *left,*right;};Tree *tree[maxn];int distance(Tree *t){ return t==NULl?0:t->dist;}void f原创 2017-07-16 09:00:43 · 279 阅读 · 0 评论 -
数据结构好的Blog链接
http://blog.youkuaiyun.com/niteip/article/details/11840691/原创 2017-07-01 13:42:03 · 396 阅读 · 0 评论 -
poj2892,线段树单点更新,区间合并
During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Except th原创 2017-07-17 10:07:22 · 333 阅读 · 0 评论 -
hdu1524线段树,扫描线
http://acm.hdu.edu.cn/showproblem.php?pid=1542题意: 一些相互可能重叠的矩形,让你求他们实际覆盖的面积之和; 对于每个矩形,给你左上角坐标,以及右下角顶点坐标#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std转载 2017-07-17 20:46:31 · 392 阅读 · 0 评论 -
单调队列: Sliding Window
Description An array of size n ≤ 10 6 is given to you. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the wind原创 2016-07-09 15:10:21 · 356 阅读 · 0 评论 -
2017ACM/ICPC广西邀请赛 K- Query on A Tree trie树合并
转载自:http://www.cnblogs.com/zxhl/p/7459240.htmlProblem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learned about one of the bit-operations, xor. He was keen o转载 2017-09-06 15:09:16 · 493 阅读 · 0 评论