数据结构
帆的孤独啊
这个作者很懒,什么都没留下…
展开
-
大数
实现核心:把数当做字符来处理/* 高精度整数:大整数,使用数组保存*/#include<stdio.h>#include<string.h>#include<time.h>//重载大整数间加,大整数和普通数间 乘 除 模struct bigInteger{ int digit[1000];//每四位作为一个digit保存 int size;/...原创 2018-03-10 12:39:51 · 191 阅读 · 0 评论 -
1003. Emergency
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the l...原创 2018-03-11 20:00:59 · 118 阅读 · 0 评论 -
1057. Stack
Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the top position) and Po...原创 2018-03-10 13:57:30 · 137 阅读 · 0 评论 -
二分求幂
/* 二分求幂:把幂指数拆成二进制的形式(幂指和等于对应数相乘) 2^27=2^(11011) temp=2 -----1 ans=ans*temp=2 temp=temp^2=4 --1 ans=ans*temp=8 temp=temp --0 ans=ans=8 temp=temp^2=16 --1 ans=ans*temp=128 temp=temp^2=256 --1 ans...原创 2018-03-10 12:49:27 · 321 阅读 · 0 评论 -
二叉树创建相关问题
#include<stdio.h>#include<queue>int pres[100],ins[100];using namespace std;struct Node{ int data; Node *lchild; Node *rchild; int layer;};void Layer(Node *root ){ queue<Nod...原创 2018-03-10 12:48:54 · 127 阅读 · 0 评论 -
迷宫问题:关键是检测及行走部分的代码
/*6 70 1 1 1 0 0 10 0 1 0 0 0 00 0 0 0 1 0 00 0 0 1 1 1 01 1 1 0 1 0 01 1 1 1 0 0 0ans=4*/#include<stdio.h>#include<queue>using namespace std;const int maxn= 100;int X[4]={0,...原创 2018-03-10 12:47:50 · 149 阅读 · 0 评论 -
进制转换
/* 不同进制转换*/#include<stdio.h>#include<string.h>int main(){ int m,n,temp=0; char buf[50]; scanf("%d%s%d",&m,buf,&n); int len=strlen(buf),weight=1; for(int i=len-1;i>=0;...原创 2018-03-10 12:46:42 · 190 阅读 · 0 评论 -
模运算的小问题
或者同一化为正数/* 1.模运算的问题:a%b=|a|%|b|,余数的符号随a 2.按数论的规定:余数不能为负,故结果可能加b变为正,如果余数是0,则结果变成了b,需要%b修正 a%b=(a%b+b)%b (除的结果可正课负,余数一定非负) 3.模运算的规律:可以放进括号中 (a*b)%c=(a%c*b%c)%c (a+b)%c=(a%c+b%c)%c*/#include<...原创 2018-03-10 12:45:39 · 208 阅读 · 0 评论 -
堆的一个实现:利用优先队列
#include<stdio.h>#include<queue>using namespace std;/*构造方法,每次从最小堆中取出权值最小的两个节点,新的双亲节点权值为两个之和,再放入堆中当只剩下一个节点时即为根节点,树中所有中间节点的权值和为总的路径*/priority_queue<int,vector<int>,greater<...原创 2018-03-10 12:42:50 · 212 阅读 · 0 评论 -
前序中序求后序
Test:FDXEAGXDEFAG/*涉及到二叉树的问题最好不用动态申请,对内存的管理很麻烦采用预分配的静态数组*///本题目由前序和中序得到后序,方法:先构造二叉树,再进行#include<stdio.h>#include<string.h>struct Node{ Node *lchild; Node* rchild; char data...原创 2018-03-10 12:41:55 · 164 阅读 · 0 评论 -
二叉排序树BST 静态实现
51 6 5 9 8/*二叉排序树的建立*/#include<stdio.h>#include<string.h>struct Node{ Node* lchild; Node* rchild; int data;}Tree[101];int loc;Node *creat(){ Tree[loc].lchild=Tree[loc].rchil...原创 2018-03-10 12:41:05 · 302 阅读 · 0 评论 -
正则表达式
正则表达式是按一定模式匹配特定字符串(所有有意义特殊字符都要以\转义)1.基本操作\d 匹配数字(decimal) \w(word)字母或数字,不包括特殊字符. 匹配任意字符 *任意字符(含0个) +至少一个字符? 0或1个字符 {n}n个字符 {n-m}表示n-m个字符注意以上*+?等加在一个字符后面 特殊情况: r'^(\d...原创 2018-05-28 20:53:29 · 128 阅读 · 0 评论