随笔分类 -  PAT

摘要:No.1119 题目:由前序后序二叉树序列,推中序,判断是否唯一后输出一组中序序列 思路:前序从前向后找,后序从后向前找,观察正反样例可知,前后序树不唯一在于单一子树是否为左右子树。 判断特征:通过查找后序序列中最后一个结点的前一个在先序中的位置,来确定是否可以划分左右孩子,如果不能, 就将其划分为 阅读全文
posted @ 2016-11-26 00:18 demianzhang 阅读(1831) 评论(0) 推荐(0)
摘要:1115 题目:二叉排序树,统计最后两层节点个数 思路:数组格式存储,insert建树,dfs遍历 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; typed 阅读全文
posted @ 2016-11-26 00:17 demianzhang 阅读(394) 评论(0) 推荐(0)
摘要:并查集合并 #include<iostream> using namespace std; const int MAX = 10010; int father[MAX],root[MAX]; int findfather(int x){ if(x==father[x]) return x; else 阅读全文
posted @ 2016-11-25 20:51 demianzhang 阅读(753) 评论(0) 推荐(0)
摘要:https://www.patest.cn/contests/pat-a-practise/1022 直接模拟, 输入,按id排序,检索 #include <iostream> #include <string> #include <algorithm> using namespace std; s 阅读全文
posted @ 2016-11-22 18:12 demianzhang 阅读(470) 评论(0) 推荐(0)
摘要:https://www.patest.cn/contests/pat-a-practise/1030 找最短路,如果有多条找最小消耗的,相当于找两次最短路,可以直接dfs,数据小不会超时。 #include<cstdio> #include<string> #include<cstring> #in 阅读全文
posted @ 2016-11-22 17:31 demianzhang 阅读(350) 评论(0) 推荐(0)
摘要:https://www.patest.cn/contests/pat-a-practise/1018 先用Dijkstra算出最短路,然后二分答案来验证,顺便求出剩余最小,然后再从终点dfs回去求出路径 #include<cstdio> #include<string> #include<cstri 阅读全文
posted @ 2016-11-22 16:58 demianzhang 阅读(565) 评论(0) 推荐(0)
摘要:题目:https://www.patest.cn/contests/pat-a-practise/1016 思路:用结构体存储,按照名字和日期排序,然后先判断是否有效,然后输出,时间加减直接暴力即可 阅读全文
posted @ 2016-11-19 01:06 demianzhang 阅读(392) 评论(0) 推荐(0)
摘要:https://www.patest.cn/contests/pat-a-practise/1013 思路:并查集合并 阅读全文
posted @ 2016-11-17 16:12 demianzhang 阅读(297) 评论(0) 推荐(0)
摘要:题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题。 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队、入队。 注意点:即使到关门时间,已经在服务中的客户(窗口第一个,接待时间早于关门时间)还是可以被服务的。其它的 阅读全文
posted @ 2016-11-16 18:50 demianzhang 阅读(528) 评论(0) 推荐(1)
摘要:题目链接:https://www.patest.cn/contests/pat-a-practise/1004 大意:输出按层次输出每层无孩子结点的个数 思路:vector存储结点,dfs遍历 阅读全文
posted @ 2016-11-14 18:23 demianzhang 阅读(209) 评论(0) 推荐(0)