- 博客(10)
- 资源 (3)
- 收藏
- 关注
原创 Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure./** * Definition for binary tree * struct TreeNode { * int val; *
2015-01-09 16:24:13
320
原创 Validate Binary Search Tree
方案一:本方法,先遍历左子树,然后又子树。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
2014-12-28 16:36:43
240
原创 区间图着色问题
区间图着色问题#include using namespace std;const int N=11;int recursive_act_select(int s[],int f[], int k, int n){ int m=k+1; while(m<=n&&s[m]<f[k]) m+=1; if(m<=n) {
2014-11-26 21:29:13
391
原创 poj1458最长公共子序列
#include #include #include using namespace std;const int maxn=1005;char str1[maxn],str2[maxn];int dp[maxn][maxn];int main(){ int M,N,i,j; while(scanf("%s%s",str1,str2)==2) {
2014-11-12 20:36:45
298
转载 局部数组过大导致编译栈区溢出问题
在开始ACM的道路上,很多时候会碰到很大的数据范围,而且要用到数组来进行存储;可能会碰到以下的问题:[cpp] view plaincopyprint?#include int main() { int n, a[10000005]; //局部 while(~scanf("%d", &n)
2014-11-09 21:02:35
1750
原创 动态规划-最长公共子序列
#include #define N 6#define M 7using namespace std;int Lcs_Length(char x[],char y[],int b[M][N],int c[M+1][N+1]){ int i,j; for(i=0;i<=M;i++) { c[i][0]=0; } for(i=0;i<
2014-11-09 17:18:21
242
原创 动态规划-钢条切割
#include using namespace std;int cut_rod(int p[],int n){ if(n==0) return 0; int q=-100; for(int i=1;i<=n;i++) { q=max(q,p[i-1]+cut_rod(p,n-i)); } return q;}int *
2014-11-08 19:23:49
346
原创 翻转单词
#include #include using namespace std;void *reversem (void * pointer,const size_t mem_n);void *reverse_adjacent_m(void * pointer,const size_t head_size,const size_t total_size);void *reverse
2014-11-07 20:54:56
210
转载 交换两段连续(不连续)内存<转>
在《编程珠玑,第二版》和《编程之美》中都有关于交换两段连续的内存块的题目,而且非常经典,交换两段连续内存块的问题又可以延伸到交换两段不连续内存块的问题,无论是哪种情况都需要一个基本操作:反转内存块。反转内存时,比较简单,可以两个指针同时走,也可以一个指针,随意,实现如下:01 // reverse the memory block02 // goal: |12345| -> |
2014-11-06 21:40:07
444
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人