数据结构
文章平均质量分 57
二分查找
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
UVA133 The Dole Queue
Description In a serious attempt to downsize (reduce) the dole queue, The New National Green Labour Rhinoceros Party has decided on the following strategy. Every day all dole applicants will be place原创 2014-07-20 20:40:03 · 494 阅读 · 0 评论 -
UVA297
Quadtrees A quadtree is a representation format used to encode images. The fundamental ideabehind the quadtree is that any image can be split into four quadrants. Each quadrant mayagain be原创 2014-07-25 18:28:32 · 564 阅读 · 0 评论 -
UVA784
还是普通的DFS,没有任何坑。。原创 2014-07-26 10:49:08 · 527 阅读 · 0 评论 -
UVA673 Parentheses Balance
Parentheses Balance You are given a string consisting of parentheses () and []. A string of this type is said to be correct: (a) if it is the empty string (b) if A and B are correct, AB原创 2014-07-20 20:32:01 · 449 阅读 · 0 评论 -
uva10308(树)
题意: 有几个城镇,要建路,不能存在环,问距离最远的两个城镇,距离多远; 给出的一系列边(u到v)以及距离,空行代表一组样例结束; 思路: 这就是一棵无根树,我们可以以任意节点做根(我用1,因为每组样例肯定都有1); 然后就是从根开始算,以这个节点为中转,最大的值肯定是他最长的两个儿子的和; 我们只要每次都算当前节点最长的两个儿子的和,再更新最终结果,然后把最长的儿子返回给它的原创 2015-01-12 18:45:11 · 362 阅读 · 0 评论 -
uva11988(链表)
题意: 给一串字符,'['相当于home键(跳到最开始),']'相当于end(跳到最末尾) 问编辑出来的这一段文字是什么样; 思路: 用链表,碰到'['后,接下去的文字存入结构体,并且插入链表的开头, 碰到']'后,接下去文字存入结构体,插入链表的末尾; 结构储存,我用的是存所在位置的办法,这一个节点存的值是原串的哪个位置到哪个位置; AC代码: #incl原创 2015-03-25 20:27:04 · 715 阅读 · 0 评论 -
uva11235(RMQ)
题意: 给出一个非降序排序;每次询问区间(i,j); 给出区间内出现最多的数字出现了几次; 非降序就是一样的数字会连在一起,并且升序; 思路: 看训练指南吧; ac代码; #include #include #include #include #include using namespace std; const int N = 100000 + 5; int n,原创 2015-03-27 20:13:36 · 542 阅读 · 0 评论 -
uvalive3942(前缀树)
题意: 给出一个字符串,然后给出n个单词,问这个串分解成单词,有几种分法; 思路: 用Trie树; #include #include #include #include using namespace std; const int N = 300000 + 5; const int MOD = 20071027; char s[N]; int val[N], c原创 2015-03-30 19:43:23 · 439 阅读 · 0 评论 -
uva11987(并查集)
题意: 给出数字数量和命令数量; 1 u v 把u和v所在的集合并起来; 2 u v 把u 这个元素放到v所在的集合; 3 u 输出u所在集合的数量,和和; 思路: 1和3都是普通的并查集,但是2的话,如果把一个集合的根移走了,那结构就坏了; 所以执行2的时候要重新创造一个ID代替: #include #include const int maxn = 2e5 + 5原创 2015-03-31 19:34:22 · 472 阅读 · 0 评论 -
uva11997(优先队列,归并)
题意: k个数组,每个数字k个值; 如果每个数组取一个值相加,那么总共有k^k种结果,取前k小的值,输出; 思路: 首先我们两个数组,两个数组找出前k小的和了,在加入第三个,这样一直两两算; 因为两个数组取出前k小的和了;那么加入第三个数组后,那么新的前k小肯定是第三个数组的值和那之前前k的值的和; 而求两个数组,和的前k小,我们可以用优先队列,加上一个动态规划; 只有AB两原创 2015-03-24 19:42:20 · 589 阅读 · 0 评论 -
uva11995(栈,队列,优先队列)
题意: 1代表放入; 2代表拿出; 问可能是哪种数据结构; 思路: 将题目提供的三种数据结构拿进去模拟一下就行了; #include #include #include #include #include using namespace std; queue q; stack s; priority_queue pq; int main() { int n; in原创 2015-03-24 18:56:06 · 710 阅读 · 0 评论 -
uva136(优先队列)
题意: 不能被2,3,5以外的素数整除的数,称为丑数;找出第1500个丑数; 思路: 用优先队列和map判重; 如果x是丑数,则2x,3x,5x都是丑数; 不停的放出优先队列; 并取出队头(最小的数)x; 要判断这个数是否已经访问过; 找到第1500个输出; #include #include #include #include #include #define原创 2015-03-31 20:20:50 · 1226 阅读 · 0 评论 -
uvaliva3027(并查集)
题意: 如果是Iuv则是把u的父节点设置为v;并且u到v的距离为|u-v| % 1000; 如果Eu 则输出u到根的距离; O结束; 思路: 在合并阶段就是普通的并查集,但还需要算一个距离: 但每次查询时,就应该把距离累加起来,并记录下来: AC代码: #include #include #include using namespace std; const in原创 2015-03-24 20:35:01 · 510 阅读 · 0 评论 -
UVA327
题目很简单就是a代表1,b代表2,去计算式子的值,如果是i原创 2014-07-25 14:41:53 · 585 阅读 · 0 评论 -
UVA712
题目的意思是给一棵完全二叉树原创 2014-07-24 21:51:06 · 1651 阅读 · 0 评论 -
UVA10562
题目的意思就是gen #include #include using namespace std ; const int maxn = 210 ; char str[maxn][maxn] ; char node[maxn] ; int rcount ; int ncount ; void init() { rcount = 0 ; ncount = 0 ;原创 2014-07-25 13:50:55 · 1183 阅读 · 0 评论 -
UVA127 "Accordian" Patience
这是一个堆纸牌游戏,首先52张牌摊开原创 2014-07-20 20:55:09 · 573 阅读 · 0 评论 -
UVA101 The Blocks Problem
思路就是用栈来模拟,一开始就是n个栈。每个栈里都是一个元素,然后按照指令移,在这个栈里pop()掉它,在另一个栈里push()进去。。 分四种情况来做移动,每种情况处理方式不一样。要注意如果是一堆移过去,因为还是要按照这个顺序,多以要先把这一堆放到另一个数组,再按顺序pushj进去。 模拟完输出即可。。原创 2014-07-21 14:42:10 · 1294 阅读 · 0 评论 -
UVA10152 ShellSort
Problem D: ShellSort He made each turtle stand on another one's back And he piled them all up in a nine-turtle stack. And then Yertle climbed up. He sat down on the pile. What a wonderful view! H原创 2014-07-21 15:11:02 · 569 阅读 · 0 评论 -
UVA11111 Generalized Matrioshkas
题目意思就是一排套娃,里面的必须小于外面的原创 2014-07-21 20:51:47 · 622 阅读 · 0 评论 -
UVA442 Matrix Chain Multiplication
Matrix Chain Multiplication Suppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices.Since matrix multiplication is associative, the order in which multip原创 2014-07-21 17:01:12 · 551 阅读 · 0 评论 -
UVA11234 Expressions
建树时就是碰到小写,就建个小树,左子树右子数都是空,压入栈; 碰到大写,也要建个小树,并把栈顶两个元素取出来,作为做子树和右子树。。在把新树压入栈 建完后栈顶就是这个树的根,采用广搜遍历就行。。原创 2014-07-22 14:20:21 · 647 阅读 · 0 评论 -
UVA540
题目的意思就是就t个队伍原创 2014-07-22 09:11:39 · 652 阅读 · 0 评论 -
UVA10050 Hartals
题目意思就是 第一行是测试组数。每组给出你n原创 2014-07-22 19:18:31 · 709 阅读 · 0 评论 -
UVA112
题目的意思就是先给出一个shu根据给出的树,原创 2014-07-23 20:36:54 · 613 阅读 · 0 评论 -
UVA548
这道题目意思就是给你一棵shu原创 2014-07-24 14:55:14 · 486 阅读 · 0 评论 -
UVA699
题目的意思是根据给出的先序遍历,原创 2014-07-24 21:50:17 · 1667 阅读 · 0 评论 -
UVA839
每行的四个数据意思是,左边的重量,左边的力矩原创 2014-07-25 10:37:36 · 763 阅读 · 0 评论 -
uva11992(线段树-区间修改)
线段树区间修改模板 #include #include #include using namespace std; #define INF 0x3f3f3f3f const int maxn = 1000005 << 2; int sum[maxn], maxv[maxn], minv[maxn], setv[maxn], addv[maxn]; int ansmin, ansmax, row,原创 2015-04-07 19:47:20 · 459 阅读 · 0 评论
分享