数据结构及算法
文章平均质量分 64
caoruntaogmail
这个作者很懒,什么都没留下…
展开
-
平衡二叉树思想及C语言实现
[转]http://blogold.chinaunix.net/u3/105029/showart_2320608.html 形态匀称的二叉树称为平衡二叉树 (Balanced binary tree) ,其严格定义是: 一棵空树是平衡二叉树;若 T 是一棵非空二叉树,其左、右子树为 TL 和 TR ,令 hl 和 hr 分别为左、右子树的深度。当且仅当 ①TL 、 TR 都是平衡二...原创 2011-04-23 16:15:07 · 175 阅读 · 0 评论 -
DP:poj1163 The Triangle
[转]http://old.blog.edu.cn/user3/dongshan/archives/2006/1466731.shtmlThe Triangle Time Limit:1000MS Memory Limit:10000KTotal Submit:3394 Accepted:1971 Description73 88 1 02 7 4 44 5 ...原创 2011-08-17 17:54:42 · 79 阅读 · 0 评论 -
DP:poj1579 Function Run Fun
[转]http://blog.csdn.net/zxy_snow/article/details/6168942Function Run FunTime Limit:1000msMemory limit:10000kB题目描述We all love recursion! Don't we?Consider a three-parameter rec...原创 2011-08-17 19:33:50 · 84 阅读 · 0 评论 -
DP:poj1661 Help Jimmy
[转]http://blog.csdn.net/zxy_snow/article/details/5771229 此题目的“子问题”是什么呢? n Jimmy 跳到一块板上后,可以有两种选择,向左走或向右走。走到左端和走到右端所需的时间,容易算出。 n 如果我们能知道,以左端为起点到达地面的最短时间,和以右端为起点到达地面的最短时间,那么向左走还是向右走,就很容选择了。 ...原创 2011-08-17 20:02:53 · 95 阅读 · 0 评论 -
DP:zoj 1074 || poj 1050 To the Max
[转]http://blog.csdn.net/zxy_snow/article/details/5998184#include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>#define N 101using namespace std;int Maxsum...原创 2011-08-17 20:17:19 · 90 阅读 · 0 评论 -
DP:zoj 1108 FatMouse's Speed
【转】http://blog.csdn.net/zxy_snow/article/details/6002534#include <stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>#include <limits.h>#include <stack...原创 2011-08-17 20:50:00 · 94 阅读 · 0 评论 -
DP:zoj 2224 || poj 2063 Investment(完全背包)
[转]http://blog.csdn.net/zxy_snow/article/details/6021316 等于求year次完全背包,完全背包外面再套层循环即可。#include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>using namespa...原创 2011-08-17 21:29:16 · 144 阅读 · 0 评论 -
DP:zoj 2014 || poj 1384 Piggy-Bank(完全背包简单变形)
【转】http://blog.csdn.net/zxy_snow/article/details/6023963 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>using namespace std;int main(void){ int ...原创 2011-08-17 21:59:18 · 95 阅读 · 0 评论 -
DP:zoj 1733 || poj 1458 Common Subsequence(最长公共子序列)
【转】http://blog.csdn.net/zxy_snow/article/details/6037072#include <stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>#define MAXLEN 300using namespace std;int m...原创 2011-08-17 22:12:35 · 93 阅读 · 0 评论 -
DP:poj 3628 Bookshelf 2( 0-1背包)
【转】http://blog.csdn.net/zxy_snow/article/details/6052676 这个相当于体积和价值一样大的01背包。 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>#include <alg...原创 2011-08-17 22:41:46 · 89 阅读 · 0 评论 -
DP:poj 3624 Charm Bracelet (0-1背包)
【转】http://blog.csdn.net/zxy_snow/article/details/6003790 一维:#include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>using namespace std;int bag[12900];...原创 2011-08-17 22:56:42 · 80 阅读 · 0 评论 -
搜索:poj 3278 Catch That Cow(广搜)
【转】http://blog.csdn.net/zxy_snow/article/details/5738154 #include <stdio.h>#include <stdlib.h>#include <string.h>int Q[300000];int count[300000];int sta[300000];int n,head,tail...原创 2011-08-17 23:26:17 · 87 阅读 · 0 评论 -
搜索:zoj 1005 Jugs || poj 1606 (广搜做法)
【转】http://blog.csdn.net/zxy_snow/article/details/5740824#include <stdio.h>#include <stdlib.h>#define Afull 1#define Bfull 2#define Aempty 3#define Bempty 4#define AtoB 5#define BtoA 6 ...原创 2011-08-18 11:20:55 · 127 阅读 · 0 评论 -
搜索:zoj 1091 Knight Moves (广搜)
【转】http://blog.csdn.net/zxy_snow/article/details/5741881#include <stdio.h>#include <stdlib.h>#include <string.h>int state[9][9];int count[9][9];int Queue[100000];int step[8][2] = {...原创 2011-08-18 11:42:57 · 123 阅读 · 0 评论 -
搜索:zoj 2100 Seeding(DFS)
【转】http://blog.csdn.net/zxy_snow/article/details/5941464#include <stdio.h>#include <stdlib.h>#include <iostream>using namespace std;int visit[8][8];int n,m,ok;int dir[8...原创 2011-08-18 11:58:07 · 83 阅读 · 0 评论 -
搜索:zoj 1089 || poj 2245 Lotto(DFS)
【转】http://blog.csdn.net/zxy_snow/article/details/5947090#include <stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>using namespace std;int n,num[14]...原创 2011-08-18 15:34:04 · 101 阅读 · 0 评论 -
搜索:poj 1154 LETTERS(DFS)
【转】http://blog.csdn.net/zxy_snow/article/details/5947160#include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>using namespace std;int visit[30]...原创 2011-08-18 15:48:34 · 97 阅读 · 0 评论 -
搜索:zoj 1709 || poj 1562 Oil Deposits(DFS )
【转】http://blog.csdn.net/zxy_snow/article/details/5947298 #include<stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>using namespace std;int map[110...原创 2011-08-18 16:14:03 · 114 阅读 · 0 评论 -
搜索:zoj 1047 || poj 1111 Image Perimeters(DFS)
【转】http://blog.csdn.net/zxy_snow/article/details/5947376/* * */#include<stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>using namespace std;i...原创 2011-08-18 16:44:51 · 111 阅读 · 0 评论 -
搜索:poj 3620 Avoid The Lakes(DFS)
【转】http://blog.csdn.net/zxy_snow/article/details/5947541 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>using namespace std;int map[11...原创 2011-08-18 17:35:51 · 91 阅读 · 0 评论 -
搜索:poj 2386 Lake Counting(DFS)
[转]http://blog.csdn.net/zxy_snow/article/details/5948458 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>using namespace std;int n,m;...原创 2011-08-19 10:47:49 · 67 阅读 · 0 评论 -
八皇后 DFS
【转】http://blog.csdn.net/zxy_snow/article/details/5949706 //八皇后#include <stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>using namespace std;con...原创 2011-08-19 11:01:31 · 147 阅读 · 0 评论 -
数论:zoj 2723 Semi-Prime
【转】 #include <stdio.h>#include <stdlib.h>#include <iostream>using namespace std;int prim[1000002];void pri(){ prim[0] = prim[1] = 0; for(int i=2; i<=1000000; i...原创 2011-08-19 11:20:52 · 172 阅读 · 0 评论 -
搜索:zoj 1002 Fire Net(DFS)
[转]http://blog.csdn.net/zxy_snow/article/details/5952668 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>using namespace std;int visit[...原创 2011-08-19 12:06:07 · 85 阅读 · 0 评论 -
搜索:Codeforces Beta Round (BFS)
【转】http://blog.csdn.net/zxy_snow/article/details/5952710 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>#include <queue>using na...原创 2011-08-19 12:12:21 · 71 阅读 · 0 评论 -
搜索:poj 1321 棋盘问题 (DFS )
[转]http://poj.org/problem?id=1321 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>using namespace std;int map[10][10];int n,k,cou,sum...原创 2011-08-19 15:03:46 · 96 阅读 · 0 评论 -
zoj 1711 || poj 1564 Sum It Up(DFS)
【转】http://blog.csdn.net/zxy_snow/article/details/5959956 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>using namespace std;int map[13...原创 2011-08-19 15:46:54 · 94 阅读 · 0 评论 -
搜索:zoj 2734 Exchange Cards(DFS)
【转】http://blog.csdn.net/zxy_snow/article/details/6005768 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>using namespace std;int sum,wa...原创 2011-08-19 16:13:33 · 104 阅读 · 0 评论 -
搜索:zoj 2165 || poj 1979 Red and Black(BFS)
[转]http://blog.csdn.net/zxy_snow/article/details/6157112 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>#include <queue>using na...原创 2011-08-19 16:47:09 · 96 阅读 · 0 评论 -
数论:zoj 2277 The Gate to Freedom
【转】http://blog.csdn.net/zxy_snow/article/details/5938144 对于N^N = X两边取对数 N * LOG N = LOGX 求出Y = N*LOGN 对Y取小数 = z X的最高位与Z的第一个非0位有关(因为10的整数次方的最高位都是1) 比如 10^10.5 它等于10^10*10^0...原创 2011-08-19 17:18:00 · 327 阅读 · 0 评论 -
数论:zoj 2105 Number Sequence
【转】http://blog.csdn.net/zxy_snow/article/details/5938336 因为公式是f(n) = (A * f(n – 1) + B * f(n – 2)) mod 7,所以f(n)=(A%7*f(n-1)+B%7*f(n-2))%7,A%7与B%7的值的范围只有0~6,也就是说循环体最大是49。 #include <stdio.h&g...原创 2011-08-19 17:49:37 · 104 阅读 · 0 评论 -
数论:zoj 2060 Fibonacci Again
[转]http://blog.csdn.net/zxy_snow/article/details/5939060 (a+b)%n = (a%n + b%n)%n 【解题思路1】:最简单的思路,开一个大小为n的数组,初始化为0,遍历一遍,如果某一项满足条件则设置为1,就不多说了,代码如下: #include <stdio.h>#include...原创 2011-08-19 18:50:45 · 103 阅读 · 0 评论 -
数论:zoj 1730 || poj 1455 Crazy Tea Party
【转】http://blog.csdn.net/zxy_snow/article/details/5993154 类似冒泡程序如果所有人是线性排列,那我们的工作就是类似冒泡程序做的工作:1,2,3,4,5变为5,4,3,2,1 ,耗时n(n-1)/2但是出现了环,也就是说1,2,3,4,5变为3,2,1,5,4也可满足条件 我们可以把这个环等分成两个部分 ,每个部分看成是线性的,再把它们...原创 2011-08-19 19:13:46 · 147 阅读 · 0 评论 -
数论:zoj 1951 || poj 2262 Goldbach's Conjecture
【转】http://blog.csdn.net/zxy_snow/article/details/6002626 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>#define MAX 1000001using na...原创 2011-08-19 19:25:49 · 108 阅读 · 0 评论 -
数论:zoj 2829 Beautiful Number
【转】http://blog.csdn.net/zxy_snow/article/details/6007526 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>using namespace std;int num[22...原创 2011-08-19 19:36:35 · 110 阅读 · 0 评论 -
数论:zoj 1797 Least Common Multiple
【转】http://blog.csdn.net/zxy_snow/article/details/6011166 #include <stdio.h>#include <stdlib.h>#include <iostream>#include <memory.h>#define MAX 10001using namespa...原创 2011-08-19 19:53:51 · 88 阅读 · 0 评论 -
数论:zoj 2818 || poj 3100 Root of the Problem
【转】http://blog.csdn.net/zxy_snow/article/details/6036148#include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>#include <math.h>using name...原创 2011-08-19 19:59:57 · 109 阅读 · 0 评论 -
数论:zoj 1526 Big Number
【转】http://blog.csdn.net/wmbol/article/details/5454093 ∵N! = N * (N - 1) * ( N - 2)····*2∴log(N!) = log(N) + log(N - 1) + ······ + log2所以阶乘的位数n = 1 + log(N) + log(N - 1) + ······ + log2; /*...原创 2011-08-19 20:13:59 · 125 阅读 · 0 评论 -
数论:zoj 1871 || poj 2590 Steps
【转】http://hi.baidu.com/sunkehappy/blog/item/0440a83e214f143470cf6ccc.html #include <iostream>#define DEBUG 1using namespace std ;int from, to ;int stimu( ){ int i, step = 2 ...原创 2011-08-19 20:41:05 · 140 阅读 · 0 评论 -
数论:zoj 1577 GCD & LCM
[转]http://cupdish.com/2011/08/zoj-1577-gcd-lcm-%E8%A7%A3%E9%A2%98%E6%8A%A5%E5%91%8A/ #include <iostream>#include <cmath> using namespace std; int main(){ int a,b,x,ans,c...原创 2011-08-19 21:42:42 · 101 阅读 · 0 评论