第6章 数据结构基础
文章平均质量分 79
01的世界
有时,失去了才懂得珍惜
展开
-
例题6-5 移动盒子 UVa 12657 链表(模拟链表)
分析:看到这题,就想用list,自己写了好久,其中erase和insert需要注意好多东西,好不容易搞定了,提交总是超时。大概list的遍历会很慢吧。书上用的是数组形式双向链表,学习了一下,AC了。#include #include #include #include #include #include #include#include#define LL long原创 2015-09-16 16:28:51 · 458 阅读 · 0 评论 -
习题6-3 二叉树的重建 UVa 536
题意:输入一棵树的先序遍历和中序遍历,输出后序遍历Sample Input DBACEGF ABCDEFGBCAD CBADSample Output ACBFGEDCDAB分析:二叉树是递归定义的,先序遍历的第一个节点就是根节点,然后在中序遍历中找到根节点,分成左子树和右子树,每个左子树和右子树也是二叉树,规律都是一样的,后序遍历是先兆左子树,在右子树,在根节原创 2015-09-30 22:07:57 · 343 阅读 · 0 评论 -
例题 6-12 油田 UVa 572 用dfs求连通块
572 - Oil DepositsTime limit: 3.000 secondsOil DepositsThe GeoSurvComp geologic survey company is responsible fordetecting underground oil deposits. GeoSurvComp works with onelarge r原创 2015-09-18 22:25:04 · 655 阅读 · 0 评论 -
例题6-3 矩阵连乘(栈)UVa 442
UVA - 442 Matrix Chain Multiplication Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit Status Description Suppose you have原创 2015-05-13 22:14:03 · 415 阅读 · 0 评论 -
例题6-2 铁轨(栈)
UVA - 514RailsTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmitStatus DescriptionThere is a famous railway station in PopPush Ci原创 2015-05-13 23:47:13 · 496 阅读 · 0 评论 -
例题6-15 给任务排序 UVA 10305(拓扑排序)
自己写的代码:1ms#include#include#include#include#includeusing namespace std;int a[105]; int n,m; int x,y; void judge() { int x1,y1; for(int i=1;i<=n;i++) { if(x==a[i])x1=i;原创 2015-06-09 15:38:50 · 761 阅读 · 0 评论 -
UVa 455 周期串
Periodic Strings A character string is said to have period k if it can be formed by concatenating one or more repetitions of another string of lengthk. For example, the string "abcabcabcab原创 2015-07-07 21:51:39 · 470 阅读 · 0 评论 -
UVa 10562 看图写树
需要注意的是节点是除了“-”,“|”,和空格的其他字符,节点无子树,要输出()。书上的代码,主要学习下一些函数的用法:#include#include#include#includeusing namespace std;const int maxn=200+10;int n;char buf[maxn][maxn];void dfs(int r,int c){原创 2015-06-12 00:02:27 · 431 阅读 · 0 评论 -
例题6-10 下落的树叶 UVa 699
The Falling LeavesTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmitStatus DescriptionEach year, fall in the North Central region i原创 2015-05-27 20:50:17 · 384 阅读 · 0 评论 -
习题6-4 骑士的移动 UVa 439
UVA - 439Knight MovesTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmitStatus DescriptionA friend of you is doing research on t原创 2015-07-12 20:59:11 · 464 阅读 · 0 评论 -
习题6-6 修改天平 UVa 12166 二叉树 *
题意:给一个深度不超过16的二叉树,代表一个天平。每根杆都悬挂在中间,每个秤砣的重量已知。至少修改多少个秤砣的重量才能让天平平衡?分析:自己写了一会没写出来,搜的题解。因为要想修改数量最少,那么至少有一个不会修改,二叉树每一层的权重是不一样的,比如说第一层‘右子树一个秤砣的重量是3,和第二层一个秤砣的重量3比较,第二层的那个3如果不变,那么第一层左子树的重量就是6,所以说第一层右子树的那个3需原创 2015-10-01 15:13:17 · 527 阅读 · 0 评论 -
例题6-16 单词 并查集判断连通+有向图欧拉路规律
Play on WordsSome of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the pu原创 2015-09-27 21:01:48 · 558 阅读 · 0 评论 -
习题 6-1 平衡的括号 UVa 673
题意:一个字符串,包含空行,(,),[ ]判断括号是否合法分析:栈操作,如果是[,(,则入栈,如果)],则判断是否栈顶( ]相搭配。具体看代码#include#include#include#include#include#includeusing namespace std;int main(){ int T; char c; string s原创 2015-09-30 16:49:24 · 403 阅读 · 0 评论 -
例题6-9 天平 UVa 839 递归
Not soMobile Before being an ubiquous communications gadget, amobile was just a structure made of strings and wiressuspending colourfull things. This kind of mobile is usually foundhanging over crad原创 2015-09-18 10:32:55 · 358 阅读 · 0 评论 -
例题 6-7 树的层次遍历 UVa 122 建树+宽度优先遍历
BackgroundTrees are fundamental in many branches of computer science. Current state-of-the art parallel computers such as Thinking Machines' CM-5 are based onfat trees. Quad- and octal-trees are原创 2015-09-16 22:41:47 · 453 阅读 · 0 评论 -
例题 6-11 四分树 UVa 297
Quadtrees A quadtree is a representation format used to encode images. The fundamental idea behind the quadtree is that any image can be split into four quadrants. Each quadrant may agai原创 2015-09-18 12:22:04 · 414 阅读 · 0 评论 -
例题6-1 并行程序模拟 UVa210 双端队列
concurrency simulatorPrograms executed concurrently on a uniprocessor system appear to be executed at the same time, but in reality the single CPU alternates between the programs, executing so原创 2015-09-15 19:48:23 · 5336 阅读 · 3 评论 -
例题6-4 破损的键盘 UVa 11988
题意:字符'['表示句首,就是光标移到了句首,’】‘表示句尾分析:这题看到有人用双端队列,把[加入队首,】加入队尾,再按照队列中的顺序输出#include #include #include #include #include using namespace std;char str[100010];int main(){ // freopen("f.txt","r",原创 2015-09-16 08:58:26 · 736 阅读 · 0 评论 -
例题 6-6 小球下落(Dropping Balls) UVa 679 二叉树规律
这题如果按照书上给的第一种方法会超时,不过那种模拟开关操作的方法是值得学习的分析:直接模拟最后一个小球的路线。因为二叉树的除了最后一层没有子节点,其他的每一层的小球都是一颗子二叉树的根节点,,而且每一个小球都会落在根节点上,前两而小球必定一个往左走,一个往右走,所以说落到每一层节点上的小球,只需知道他是第几个落在上面的,就知道他要往左还是往右走了,最后一层不是根节点不能走,所以需要判断D-1层原创 2015-09-16 18:21:04 · 600 阅读 · 0 评论 -
习题6-2 S树 UVa 712
UVA - 712 S-Trees Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit原创 2015-07-12 00:02:26 · 428 阅读 · 0 评论 -
习题6-11 树重建 UVa 10410 *
题意:输入n节点树的bfs序列和dfs序列。输出每个节点的子节点列表,其中输入序列是这样生成的:当一个节点被扩展时,其所有子节点应该按照编号从小到大的顺序被访问。Sample Input84 3 5 1 2 8 7 64 3 1 7 2 6 5 8Sample Output1: 72: 63: 1 24: 3 55: 86:7:8:分析:又没写出来,还原创 2015-10-01 19:01:03 · 444 阅读 · 0 评论 -
习题6-5巡逻机器人 UVa 1600 bfs
题目:点击打开链接分析:一道bfs题,由于到达一点需要判断经过了几个障碍,所以在vis数组中需要加上一维来表示经过的障碍物,因为到达一点的可行路径是不同的,如果单纯的用vis[x][y],来表示点的状态,会有覆盖,所以需要三维数组。其他的地方就是bfs模板了。#include#include#include#includeusing namespace std;#原创 2015-10-01 11:17:38 · 378 阅读 · 0 评论 -
例题6-8 树 Tree UVa 548 中序遍历+后序遍历建树
TreeTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmitStatus DescriptionYou are to determine the value of the leaf node in a given原创 2015-05-28 00:09:01 · 534 阅读 · 0 评论