算法笔记
石前有座桥
学生
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
堆
参照浙大MOOC数据结构 void Swap( ElementType *a, ElementType *b ) { ElementType t = *a; *a = *b; *b = t; } void PercDown( ElementType A[], int p, int N ) { /* 改编代码4.24的PercDown( MaxHeap H, int p )转载 2017-08-25 18:20:22 · 319 阅读 · 0 评论 -
LCA查找最近公共祖先
参考大佬的思路 //AC code /* 1:根据中序,先序建树 2: 用 findnode( )查看待查询节点是否存在 3:若待查询节点是存在,用 LCA( )查找最近公共祖先 其中LCA有三种: u,v都在左子树或右子树,或者u,v分别在左子树和右子树, 因此可采取如下步骤: (1)::判断当前遍历的节点是否为空,为空返回null, (2)::节...转载 2019-04-03 18:21:45 · 292 阅读 · 0 评论 -
memset按照字节赋值
memset按照字节赋值0 -1的二进制代码(补码)为 全0 和 全1所以最好使用fill对其他值赋初值#include<stdio.h> #include<math.h> #include<string.h>//memset int main(){ int a[2]; memset(a,1,sizeof(a));//memset按照字节赋值 pr...原创 2018-03-05 20:23:00 · 394 阅读 · 0 评论 -
大整数乘法
描述求两个不超过200位的非负整数的积。输入有两行,每行是一个不超过200位的非负整数,没有多余的前导0。输出一行,即相乘后的结果。结果里不能有多余的前导0,即如果结果是342,那么就不能输出为0342。样例输入12345678900 98765432100样例输出1219326311126352690000参考别人的:#include<stdlib.h> #include<...转载 2018-03-12 14:14:41 · 1673 阅读 · 0 评论 -
大整数减法
参照算法笔记P174 1065. A+B and C (64bit) (20) #include #include struct bign{ int d[1000]; int len; }; void init(bign &a){ int i; a.len=0; for(i=0;i<1000;i++){ a.d[i]=0; } } bign change(char转载 2017-07-25 19:59:07 · 333 阅读 · 0 评论 -
计算时间差
参照算法笔记P98 甲级1016. Phone Bills (25) void get_ans(int on, int off, int& time, int& money) { temp = rec[on]; while(temp.dd < rec[off].dd || temp.hh < rec[off].hh || temp.mm < rec[off]转载 2018-01-09 15:37:00 · 273 阅读 · 0 评论 -
to_string
string to_string (int val); devc++上貌似用不了 pat上可以 #include using namespace std; int main() { int a, b; cin >> a >> b; string s = to_string(a + b); int len = s.length();原创 2017-12-28 15:05:16 · 593 阅读 · 0 评论 -
二分查找
参照算法笔记P126 Shopping in Mars (25) Find Coins (25) #include //普通二分 int binarySearch(int A[],int left,int right,int x){//[0,n-1] int mid; while(left<=right){ mid=(left+right)/2; if(A[转载 2017-08-03 20:40:32 · 236 阅读 · 0 评论 -
大整数加法
参照算法笔记P172 #include #include struct bign{ int d[1000]; int len; }; void init(bign &a){ a.len=0; int i; for(i=0;i<1000;i++){ a.d[i]=0; } } bign change(char *s){ bign a; init(a); a.len=转载 2017-07-23 19:23:42 · 357 阅读 · 0 评论 -
并查集
http://blog.youkuaiyun.com/lyw_321/article/details/71372497原创 2017-08-24 18:22:26 · 359 阅读 · 0 评论 -
优先队列
#include//priority_queueq 大顶堆 #include//priority_queue,greater >q 小顶堆 using namespace std; int main(){ int n,x,i; while(scanf("%d",&n)!=EOF){ priority_queue,greater >q;//空格 for(i=0;i<n;i++){原创 2017-05-24 12:36:51 · 243 阅读 · 0 评论 -
C++字符串输入
参照算法笔记P75 char str[1000]; cin.getline(str,100); string str; getline(cin,str);转载 2017-08-02 20:40:00 · 214 阅读 · 0 评论 -
筛选素数
参照算法笔记P162 首先确定2是素数,那么2的倍数一定不是素数,标记它们。 3未被标记,则3是素数,那么那么3的倍数一定不是素数,标记它们。 4已被标记,不是素数。 5未被标记,则5是素数,那么5的倍数一定不是素数,标记它们。 。。。 const int maxn = 1000001; int prime[maxn], num = 0; bool p[maxn] =转载 2017-06-22 14:23:58 · 292 阅读 · 0 评论 -
字符串哈希
参照算法笔记P109 先假设字符串均由大写字母A~Z构成。在这个基础上,不妨把A~Z视为0~25,这样就把26个大写字母对应到了26进制中。接着,按照将26进制转化为10进制的思路,由进制的转换结论可知,在进制转换过程中,得到的10进制肯定是唯一的,由此便可实现将字符串映射为整数的需求(注意:转换成的最大整数位(int)(pow(26,len)-1),len为字符串长度) int转载 2017-06-09 10:14:29 · 778 阅读 · 0 评论 -
树的高度
int getheight(node T){ if(T){ int HL=getheight(T->left); int HR=getheight(T->right); int maxH=HL>HR?HL:HR; return maxH+1; } else{ return 0; } }原创 2017-05-21 16:14:21 · 326 阅读 · 0 评论 -
1066. Root of AVL Tree (25)
时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue An AVL tree is a self-balancing binary search tree. In an AVL tree, the heig转载 2017-05-31 17:29:54 · 351 阅读 · 0 评论 -
04-树7 二叉搜索树的操作集 (30分)
本题要求实现给定二叉搜索树的5种常用操作。 函数接口定义: BinTree Insert( BinTree BST, ElementType X ); BinTree Delete( BinTree BST, ElementType X ); Position Find( BinTree BST, ElementType X ); Position FindMin( BinTree BST原创 2017-05-15 15:31:48 · 439 阅读 · 0 评论 -
dijkstra+dfs模板
算法笔记P384.甲级1018. void dijkstra(int s){ int i,newp=s; mark[s]=1; dis[s]=0; while(1){ for(i=0;i<=n;i++){ if(mark[i]==0&&dismap[newp][i]<inf){ if(dis[i]>dis[newp]+dismap[newp][i]){原创 2017-05-08 18:30:53 · 391 阅读 · 0 评论 -
静态链表模板
参照算法笔记P263.甲级1052 //定义静态链表 struct Node{ int address; typedname data; int next; XXX;//结点的某个性质 }; //初始化 for(i=0;i<maxn;i++){ node[i].XXX=0;//设置一个正常情况下达不到的数字 } //修改XXX int p=begin转载 2017-05-16 14:44:38 · 373 阅读 · 0 评论
分享