EricYang

Tech Spot of Eric

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
上一页 1 2 3 4 5 6 7 8 ··· 18 下一页

2012年8月15日

摘要: Mondriaan's DreamTime Limit:3000MSMemory Limit:65536KTotal Submissions:7991Accepted:4605DescriptionSquares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, f 阅读全文
posted @ 2012-08-15 16:01 Eric-Yang 阅读(282) 评论(0) 推荐(0) 编辑

2012年8月13日

摘要: 1 #include <iostream> 2 3 using namespace std; 4 5 const int TREELEN=6; 6 7 typedef struct NODE 8 { 9 char chVal;10 struct NODE* pLeft;11 struct NODE* pRight;12 }NODE;13 14 void rebuild(char *pPreOrder, char *pInOrder, int treeLen, NODE **pRoot)15 {16 //前序中序序列为空,返回NULL,失败17 i... 阅读全文
posted @ 2012-08-13 22:59 Eric-Yang 阅读(173) 评论(0) 推荐(0) 编辑

2012年8月12日

摘要: zzhttp://blog.csdn.net/vividonly/article/details/6688327编程之美3.9:重建二叉树扩展问题1:如果前序和中序遍历的字母有重复的,那么怎么构造所有可能的解呢?扩展问题2:如何判断给定的前序遍历和中序遍历的结果是合理的?思路:问题1:搜索所有可能的情况,并调用扩展问题2的解决方案,判断此情况是否合理(剪枝操作),如果合法,则构造解问题2:递归判断左右子树是否合理,递归的返回条件是到达叶子节点。代码及测试情况如下: 1 /* 2 * 编程之美重建二叉树,扩展问题1,2 3 * 扩展问题1:如果前序和中序的字母可能是相同的,怎么重构出所... 阅读全文
posted @ 2012-08-12 21:35 Eric-Yang 阅读(365) 评论(0) 推荐(0) 编辑

摘要: zzhttp://www.cppblog.com/humanchao/archive/2008/04/17/47357.html有一个单链表,其中可能有一个环,也就是某个节点的next指向的是链表中在它之前的节点,这样在链表的尾部形成一环。问题:1、如何判断一个链表是不是这类链表?2、如果链表为存在环,如何找到环的入口点?解答:一、判断链表是否存在环,办法为:设置两个指针(fast, slow),初始值都指向头,slow每次前进一步,fast每次前进二步,如果链表存在环,则fast必定先进入环,而slow后进入环,两个指针必定相遇。(当然,fast先行头到尾部为NULL,则为无环链表)程序如下 阅读全文
posted @ 2012-08-12 15:07 Eric-Yang 阅读(227) 评论(0) 推荐(0) 编辑

摘要: 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 5 using namespace std; 6 7 int main() 8 { 9 char strA[10] = "abddd";10 char strB[10] = "aebdd";11 int lenA, lenB;12 lenA=strlen(strA);13 lenB=strlen(strB);14 15 //dp16 int dp[lenA+1][lenB+1];17 阅读全文
posted @ 2012-08-12 00:24 Eric-Yang 阅读(241) 评论(0) 推荐(0) 编辑

2012年8月11日

摘要: 两个字符串可以经过修改,增加, 删除一个字符作为一个操作,经过n步操作,两个字符串变为一样的,相似度就为n,求n。 1 #include <iostream> 2 #include <cstring> 3 4 using namespace std; 5 6 char strA[10] = "abddd"; 7 char strB[10] = "aebdd"; 8 9 int calcDistance(int sa, int ea, int sb, int eb)10 {11 if(sa > ea)12 {13 if(sb 阅读全文
posted @ 2012-08-11 20:36 Eric-Yang 阅读(212) 评论(0) 推荐(0) 编辑

摘要: 1 #include <iostream> 2 3 using namespace std; 4 5 char c[10][10] = 6 { 7 "", //0 8 "", //1 9 "ABC", //210 "DEF", //311 "GHI", //412 "JKL", //513 "MNO", //614 "PQRS", //715 "TUV", //816 "WXYZ", 阅读全文
posted @ 2012-08-11 20:05 Eric-Yang 阅读(252) 评论(0) 推荐(0) 编辑

摘要: zz:http://blog.csdn.net/jcwkyl/article/details/3889802这是《编程之美》的2.20题目,给出一段C#代码,要求不用电脑,理解程序并回答问题。下面是从C#代码中改写成的C++代码: 1 #include <iostream> 2 #include <limits> 3 using namespace std; 4 int main() { 5 int rg[] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 6 20,21,22,23,24,25,26,27,28,.. 阅读全文
posted @ 2012-08-11 16:12 Eric-Yang 阅读(257) 评论(0) 推荐(0) 编辑

摘要: 有一个无序,元素个数为2n的正整数数组,把这个数组分成两个n的子数组,子数组和最接近?将其转化为0/1背包问题,将容量为n的背包放入元素,元素的体积为1,重量为其大小,如何装使其接近于重量sum/2,sum为2n的和。 1 #include <iostream> 2 #include <cstring> 3 4 using namespace std; 5 6 int main() 7 { 8 int n=5; 9 int nArray[10] = {1,5,7,8,9,6,3,11,20,17};10 11 //0/1背包12 int sum=0;13 ... 阅读全文
posted @ 2012-08-11 15:33 Eric-Yang 阅读(249) 评论(0) 推荐(0) 编辑

2012年8月10日

摘要: Maximum sumTime Limit:1000MSMemory Limit:65536KTotal Submissions:27256Accepted:8329DescriptionGiven a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below:Your task is to calculate d(A).InputThe input consists of T(<=30) test cases. The number of test cases (T) is given in th 阅读全文
posted @ 2012-08-10 10:55 Eric-Yang 阅读(214) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 ··· 18 下一页