一道和Leetcode的一道题目基本上一样的题目。
给出前序遍历和中序遍历序列,要求根据这些信息恢复一颗二叉树的原貌,然后按后序遍历序列输出。
Leetcode上有给出后序和中序,恢复二叉树的。
不过其实算法都是一样的。仿佛又回到了做Leetcode题的那段岁月中了。
#include
#include
#include
using std::string;
const int...
分类:
其他好文 时间:
2014-07-06 12:24:42
阅读次数:
129
Description
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city counci...
分类:
其他好文 时间:
2014-07-06 10:53:28
阅读次数:
185
题目大意:
问的是m个字符串里,都出现过的子串。子串也可以出现在这个串的逆序串中。
思路分析:
居然wa在全5个 “a” 的数据上。
二分的时候下界不能为0。。
思路大致上是把原串和逆序串全部处理出来,放入str中,然后在每个串中间加一个没有出现过的。
此处注意输入不仅仅是字母。
然后跑一遍后缀数组。
然后用标记计数就好了。
#include
#include ...
分类:
其他好文 时间:
2014-07-06 10:07:36
阅读次数:
202
给出按最底层叶子节点到根节点的数据,然后要求重建树,前序输出最终建的树。
都是两个基本操作解决:
1 二叉树插入操作
2 前序遍历
简单题目了。
#include
#include
#include
#include
using std::vector;
using std::string;
const int MAX_B = 1024;
char buf[MAX_B...
分类:
其他好文 时间:
2014-07-06 09:54:52
阅读次数:
239
最小生成树问题。
用矩阵输入的。
不过很忧伤的是用G++ 提交AC。。C++ 就一直RE。
不过题中说了最多 100 X 100 的矩阵啊。
Logically, they are N lines of N space-separated integers. Physically, they are limited in length to 80 characters, so some l...
分类:
Web程序 时间:
2014-07-06 09:17:00
阅读次数:
312
The Game
Description
One morning, you wake up and think: "I am such a good programmer. Why not make some money?'' So you decide to write a computer game.
The game takes place on a rectangular...
分类:
其他好文 时间:
2014-07-06 09:02:34
阅读次数:
287
本题使用所谓的辗转相除法。
还需要逆过来遍历二叉树。可以想象给出的数据点是根节点,然后遍历到根节点(1,1)。
考的是根据给出的规则,总结规律的能力。
#include
namespace BinaryTree2499_1
{
int main()
{
int T, a, b, le, ri;
scanf("%d", &T);
for (int t = 1; t <= T; t...
分类:
其他好文 时间:
2014-07-06 08:11:00
阅读次数:
164
本题是求最小生成树。
给出的是坐标节点,然后需要根据这些坐标计算出各个点之间的距离。
除此就是标准的Prime算法了,能使用Prime的基本上都可以使用Kruskal。
这些经典的算法一定要多写,熟练掌握,否则很难灵活运用的。
而且经典的算法之所以为经典,原因之一是没那么容易自己凭空想象出来的,所以要熟练。
#include
#include
#include
#include ...
分类:
其他好文 时间:
2014-07-06 00:22:21
阅读次数:
338
并查集问题。。。
这题以前做过……
以前做过……
做过……
过……
不过重做时候被吭得异常之爽……
在判断 vis[i]的时候。我记得标准C++是非0 即为真。
而我用C++ 提交的时候 if(vis[i]) 去直接给我WA了。
用G++ 就AC了。。。然后改成if(vis[i]==1) 交C++ 就AC了。
特瞄的我每次初始化都把 vis[i] 都赋值为 0...
分类:
其他好文 时间:
2014-07-06 00:19:08
阅读次数:
272
又是个最小生成树问题。
Special Judge 。答案不唯一。所以样例看起来是错的。。。
又是忧伤的G++ AC。 提交C++ 就WA了。。。
又要顺道求过路大神看看。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#d...
分类:
Web程序 时间:
2014-07-05 22:53:37
阅读次数:
269