随笔分类 -  数据结构—二叉树 && 二叉排序树 && 字典树

摘要:题目题意:给n个数,m次询问,每次给一个数,求这n个数里与这个数 异或 最大的数。思路:建一个类似字典数的数,把每一个数用 32位的0或者1 表示,查找从高位向底位找,优先找不同的,如果没有不同的,就找相同的。 1 #include 2 #include 3 #include 4 #inclu... 阅读全文
posted @ 2014-05-21 19:54 水门 阅读(166) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=3007题意:按照图示的改变字符串,问有多少种。。字符串。。思路:分几种排序的方法,,刚开始用map 超时(map效率不高啊。。),后来搜了一下题解,用二叉排序树。。。先贴AC代码: 1 #include 2 #include 3 ... 阅读全文
posted @ 2013-12-19 13:50 水门 阅读(323) 评论(0) 推荐(0)
摘要:题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2482感觉树这一部分掌握的真心不好,以前练习的一道题,当时不会,今天参考了一下别人的代码,出了点错误,但终于A了。。。。。 1 #include 2... 阅读全文
posted @ 2013-12-09 21:35 水门 阅读(230) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=2513参考博客:http://blog.csdn.net/lyy289065406/article/details/6647445http://www.cnblogs.com/LK1994/p/3263462.html 1 #include... 阅读全文
posted @ 2013-08-24 20:39 水门 阅读(195) 评论(0) 推荐(0)
摘要:题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2128&cid=1184 1 #include 2 #include 3 #include 4 struct tree 5 { 6 int data; 7 struct tree *l,*r; 8 }; 9 int x;10 11 void build(struct tree *root,int a)12 {13 struct tree *p;14 p=(struct tree *)malloc(sizeof(struct tree));15 if... 阅读全文
posted @ 2013-07-02 22:39 水门 阅读(712) 评论(0) 推荐(0)
摘要:题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1291以前的一个题,贴下代码; 1 #include 2 #include 3 char ans[100]; 4 5 void build(int n, char *s1, char *s2, char *s) 6 { 7 if(n <= 0) return; 8 int p = strchr(s2, s1[0])-s2; 9 build(p, s1+1, s2, s);10 build(n-p-1, s1+p... 阅读全文
posted @ 2013-07-01 22:51 水门 阅读(381) 评论(0) 推荐(0)
摘要:题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2136&cid=1184 自己重新写的: 下面的代码如果建树 不想要返回值的话,也可以这些写 void build(tree *&p) { },这样用引用可以自动 改变L和R的指向。 如果不加 阅读全文
posted @ 2013-07-01 13:37 水门 阅读(516) 评论(0) 推荐(0)
摘要:题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2137&cid=1184有关博客:http://blog.sina.com.cn/s/blog_7dc67d520100t26n.htmlhttp://www.cnblogs.com/shangyu/archive/2012/03/03/2378422.html以前做过,现在做还是不会…… 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 9 struct t... 阅读全文
posted @ 2013-06-29 12:30 水门 阅读(304) 评论(0) 推荐(0)
摘要:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=1500&cid=1147View Code 1 #include 2 #include 3 #include 4 5 struct node 6 { 7 int flag; 8 ... 阅读全文
posted @ 2013-04-07 21:02 水门 阅读(235) 评论(0) 推荐(0)