
数据结构
Minion_w
这个作者很懒,什么都没留下…
展开
-
二叉树的建立与遍历
#include<iostream> using namespace std;int num[100]; typedef struct node { struct node *left; struct node* right; char value; }BiTreeNode, *BiTree;void creatBiTree(BiTree &T) // 传引用 { c原创 2017-04-28 08:15:29 · 228 阅读 · 0 评论 -
POJ 1321(A)棋盘问题
题目连接 题目主要考点: 1、简单的递归深度遍历 2、简单的枚举(8皇后问题)(还没有研究,要继续学一下)做题感受:算法和数据结构是相辅相成的,一定不能把这两者分隔开,还有一定要把基础知识学扎实了一张有利于了解深度遍历的图: AC代码:#include<iostream> #include<cstdio> #include<cstring> #include<string> using na原创 2017-06-15 13:04:02 · 309 阅读 · 0 评论 -
UVA 1513—— Movie collection(树状数组)
树状数组的简单用法: #include using namespace std; const int maxn = 1e5 + 5; int N, M, fnew[maxn*2]; //进行操作的树状数组 int pos[maxn]; //保存原位置的数组 inline int lowbit(int x) //能够求出来管辖的区域范围 { return x&(-x); } //树状数原创 2017-08-21 08:58:54 · 286 阅读 · 0 评论 -
线段树
Code: #include using namespace std; const int MAX_N = 1 << 17; int n, dat[2*MAX_N - 1]; void init() { for(int i = 0; i < 2*n-1; i++) dat[i] = INT_MAX; } void update(int k, int a) //将x位原创 2017-09-24 11:01:26 · 207 阅读 · 0 评论 -
树状数组
Code: //树状数组 //#include #include #include #include using namespace std; const int maxn = 50010; int a[maxn]; //放元素的数组; int bit[maxn]; //树状数组 int n; int lowbit(int i) //求i这原创 2017-11-14 11:51:13 · 293 阅读 · 0 评论 -
URAL - 1090 树状数组求逆序数
题目链接 树状数组求逆序数: 相当于一个标记的思想,用1来标记每一个位置 某一位置的逆序数不就是这个位置的坐标减去他前面出现的数字(因为他前面出现的一定是比它小的,而且还是被标记了,一定符合标准) 同时还要注意初始的比较值!! Code: //#include<bits/stdc++.h //树状数组求逆序对 //错了非常多遍,今天才该对,原来凶手竟然是-1 //如果每一个的逆序对数都原创 2017-11-19 16:15:19 · 244 阅读 · 0 评论 -
线段树区间更新
Code: //线段树的区间更新 #include #include #include using namespace std; typedef long long LL; const int DAT_SIZE = (1 << 18) -1; const int maxn = 100010; int N, Q; LL A[maxn]; char T[maxn]; int L[maxn], R[原创 2017-12-01 20:27:38 · 231 阅读 · 0 评论 -
LeetCode刷题记录1——数组专项
Problem1(26) 题目描述:给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。 我的解法: 我的解法非常的简单,就是使用最常规的想法,既然不让我开辟新的数组空间,那就只能在原地删除了,既然时间复杂度没有限制,那就直接用最简单的方法(将后面的数向前逐位...原创 2019-07-23 20:20:38 · 182 阅读 · 0 评论