
算法
形形色色的人
这个作者很懒,什么都没留下…
展开
-
算法-红黑树, B树(未完待续)
红黑树的性质:1.每个节点是红的或者是黑的(废话)2.根节点是黑的3.每个叶子节点是黑的4.红色节点的两个儿子节点是黑色的5.每个结点到他的子孙节点上所有的路径包含相同数目的黑结点。...原创 2021-01-11 11:03:27 · 85 阅读 · 0 评论 -
DFS求迷宫问题
/*迷宫问题(四方向)input:16 80 1 1 1 0 1 1 11 0 1 0 1 0 1 00 1 0 0 1 1 1 10 1 1 1 0 0 1 11 0 0 1 1 0 0 00 1 1 0 0 1 1 0output:YES(1,1) (2,2) (3,1) (4,1) (5,2) (5,3) (6,4) (6,5) (5,6) (4,5) (4,6)原创 2015-08-30 20:43:35 · 977 阅读 · 1 评论 -
计数排序
#include#includeint nTestCase[300001];int nNumbers[32001];int main(){ freopen("sample_input.txt","r",stdin); int i, j, test, currrank, n, max; scanf("%d", &test); while (test--){ currrank原创 2015-08-17 17:10:54 · 648 阅读 · 0 评论 -
最小代价生成树
#includeusing namespace std;const int Max = 100;int p[Max][Max];const int maxCost = 99;int lowcost[Max];int nearest[Max];bool mark[Max];void Prime(int k,int n){ memset(lowcost, 99, sizeof(lo原创 2015-08-17 18:15:44 · 2193 阅读 · 1 评论 -
ZOJ2110 骨头的诱惑
#include#includeusing namespace std;char map[10][10];int di, dj;//门的出生点int T;bool flag;int dir[4][2] = { { -1, 0 }, { 1, 0 }, { 0, 1 }, { 0, -1 } };void dfs(int curr_x, int curr_y, int cnt)原创 2015-08-31 18:10:18 · 875 阅读 · 1 评论 -
2048小游戏主要算法实现
描述2048是一款最近较为流行的数字游戏,很多同学在课堂上研究如何得到更高的积分,以至影响了学习效果,不如自己写下这款游戏吧,这样估计也就没有玩的兴趣了。游戏的规则是:给定一个4*4的方格,开始的时候只有若干个2, 每次可以选择上下左右其中一个方向去滑动,每滑动一次,所有的数字方块都会往滑动的方向靠拢外,系统也会在空白的地方乱数出现一个数字方块,相同数字的方块在靠拢、相撞时会相加,可以原创 2015-09-02 17:36:56 · 2098 阅读 · 1 评论 -
动态规划之数字三角形
题目大意:有一个由非负整数组成的三角形,第一行只有一个数,除了最下行之外每个数的左下方和右下方各有一个数,如图 1 3 2 4 10 1 4 3 2 20从第一行的数开始,每次可以往左下或右下走一格,直到走到最下行,把沿途经过的数全部加起来,如何走才能使得这个和尽量大、#include #include u原创 2015-08-19 15:28:32 · 804 阅读 · 1 评论 -
网易游戏笔试2015—字符串压缩
题目:对字符串压缩格式包含两种类型1.字母+数字2.括号+数字例如:”A5″表示5个连续的”A”,”(A2B)3″表示3个连续的”A2B”,实际的输入会包含这两种格式的嵌套。示例:测试输入:(4表示接下来有4组输入测试数据)4(AA)2A((A2B)2)2GWANGYIA2BC4D2测试输出:51369解析转载 2015-10-12 16:40:50 · 561 阅读 · 0 评论 -
BFS求迷宫
Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze.Given Joe's location in the m原创 2015-08-31 17:50:04 · 604 阅读 · 1 评论 -
快速排序
快速排序是排序算法中用的最多,时间最快的算法。要熟练掌握。#include using namespace std;int a[] = { 57, 68, 59, 52, 72, 28, 96, 33, 24 };void Qsort( int low, int high){ if (low >= high) { return; } int first = lo原创 2015-08-22 20:57:49 · 1084 阅读 · 1 评论 -
两路合并排序
两路合并排序,时间复杂度为nlogn#includeusing namespace std;//merge two subArray,one is A[i1]~A[j1],another is A[i2]~A[j2]void MergeTwoArray(int A[],int i1,int j1,int i2,int j2){ int *tmp = new int[j原创 2015-08-14 09:12:02 · 2165 阅读 · 0 评论 -
01背包问题
01背包问题,并打印出路径#include#includeusing namespace std;#define MAX 100int f[MAX][MAX];int Path[MAX][MAX];int main(){ int Weight[] = {0,2,3,1,4,6,5}; int Value[] = {0,5,6,5,1,19,7}; in原创 2015-08-07 16:00:41 · 538 阅读 · 0 评论 -
全排列方法求解八皇后问题
#includeusing namespace std;int C[8];int res = 0;//多少组解void EightQueen(int n,int curr){ if (curr == n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (C[i] == j)原创 2015-08-25 16:01:11 · 868 阅读 · 1 评论 -
全排列
主要学习下递归的思路,没有考虑重复数的问题#includeusing namespace std;int A[5] = {1,2,3,4,5};int B[5];void permutation(int n,int curr){ if (curr == n) { for (int i = 0; i < n; i++) cout << B[i] << " ";原创 2015-08-25 15:34:59 · 634 阅读 · 1 评论 -
BFS求解迷宫问题
迷宫问题20 1 0 0 00 1 0 1 00 0 0 1 00 1 1 1 00 0 0 1 00 1 0 0 00 1 0 1 00 0 0 0 00 1 1 1 10 0 0 1 0#include#include#includeusing namespace std;int maze[5][5];in原创 2015-08-25 11:48:13 · 1374 阅读 · 1 评论 -
Dijkstra算法,求单源最短路径(包含路径)
/*测试数据 教科书 P189 G6 的邻接矩阵 其中 数字 1000000 代表无穷大61000000 1000000 10 100000 30 1001000000 1000000 5 1000000 1000000 10000001000000 1000000 1000000 50 1000000 10000001000000 1000000 1000000 1000000 10原创 2015-08-23 15:30:38 · 842 阅读 · 1 评论 -
Dijkstra算法
http://acm.hdu.edu.cn/showproblem.php?pid=2544#include #include using namespace std;const int maxnum = 105;const int maxint = 999999;int dist[maxnum]; // 表示当前点到源点的最短路径长度int cost[maxn原创 2015-08-23 22:06:59 · 1261 阅读 · 1 评论 -
简单的Stack
自己实现的简单的Stack,没有查空满,用于算法考试#includeusing namespace std;const int MAX = 100;struct MyStack{ int data[MAX]; int top;}stack={{0},0};int main(){ for(int i = 0;i<10;i++) { stack.data[s原创 2015-08-13 15:17:34 · 650 阅读 · 0 评论 -
简单的Queue
不考虑好多东西,算法考试中用得到的Queue#includeusing namespace std;const int MAX = 100;struct MyQueue{ int data[MAX]; int front; int rear;}queue={{0},0,0};int main(){ for(原创 2015-08-13 14:47:10 · 601 阅读 · 0 评论 -
算法练习
#include int x[80000];int main(){ int s,t,n,m,a; long long r; freopen("sample_input.txt","r",stdin); scanf("%d",&t); for(s=1;s<=t;s++) { scanf("%d",&n); m=-1;r原创 2015-08-07 16:54:31 · 611 阅读 · 0 评论 -
hdu 素数环1016
A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime.Note: the number o原创 2015-08-24 14:35:30 · 711 阅读 · 0 评论