-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
115 changed files
with
4,305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
## 2021-2022 数据结构 大三上学期 | ||
|
||
* 题特别多,题并不难,但就是写不完 | ||
* 往年题很多,但基本都改过 | ||
|
||
#### 一、线性结构 | ||
|
||
* 给序列,写出快排第一趟和基数排序第二趟的序列 | ||
* 链式散列 | ||
* 画出初始化后的链式散列 | ||
* 一次成功的查找需要查找的桶的个数 | ||
* 括号匹配 | ||
* 写算法思路 | ||
* 给一个表达式,画出用栈处理的过程,并判断是否匹配 | ||
* 写代码,a和b两个有序链表,用chain的迭代器和insert方法将ab的交集元素插到c中,使得c中是一个递减序列 | ||
|
||
#### 二、树形结构 | ||
|
||
* 一个满k叉树,非叶子结点数为Nk,求叶子节点数 | ||
* 这还有个题,忘了 | ||
* AVL树 | ||
* 初始化,写出每一步过程 | ||
* 删除一个元素,写出删除后的AVL树 | ||
* B-树 | ||
* 对给定的B-树,插入某个元素,问需要的磁盘访问次数 | ||
* 对上一问的B-树,删除某个元素,问需要的磁盘访问次数 | ||
|
||
#### 三、图结构 | ||
|
||
* 度为4的节点有xx个(具体数),度为3的节点有xx个(具体数),其余都是度小于3的节点,问图中总共有几个节点 | ||
* 给一个图(这个题有四问,记不清了) | ||
* 写出DFS序列和DFS树 | ||
* 写出BFS序列和BFS树 | ||
* 克鲁斯卡尔 | ||
* 克鲁斯卡尔的思想 | ||
* 用了哪些数据结构,具体怎么用的 | ||
* 根据思想,画图表示算法运行过程 | ||
|
||
#### 四、算法设计 | ||
|
||
* 小根堆 | ||
* 设计算法判断一个二叉树是否是小根堆(给出算法思想) | ||
* 根据思想写出代码,并给出适量注释 | ||
* 单源最短路 | ||
* 设计算法求源点s到任意其他点的最短路,给出算法思想(其实就是迪杰斯特拉) | ||
* 通过算法思想写代码,并给出注释 | ||
* 算法复杂度是什么 | ||
|
||
|
||
|
||
#### TMD! | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// Created by 邵嘉明 on 2021/9/28. | ||
// | ||
#include <iostream> | ||
#include <cmath> | ||
using namespace std; | ||
int n; | ||
int vIndex = 0; | ||
template<class T> | ||
void subSet(T arr[], T Sup[], T value[], int index) { | ||
// arr: 待求子集的数组 | ||
// Sup: 辅助数组,bitset | ||
// value: (子集)价值数组 | ||
// index: 当前求二进制数求到数组中那个数的索引 | ||
for(int i=0;i<=1;i++) { | ||
Sup[index] = i; | ||
if(index == n-1) { | ||
// 递归已到头,对任意元素,其sup[]均已赋值0/1,求出每个子集的价值放入其对应value[]项中 | ||
// 某子集的异或值 | ||
int tmpSum = 0; | ||
// 子集数组 | ||
int *tmp = new int[n]; | ||
// 子集数组索引 | ||
int tmpIndex = 0; | ||
// 得到一个子集 | ||
for(int j=0;j<n;j++) { | ||
if(Sup[j] == 1) { | ||
tmp[tmpIndex] = arr[j]; | ||
++ tmpIndex; | ||
} | ||
} | ||
for(int j=0;j<tmpIndex;j++) { | ||
tmpSum += (tmp[j] * (j+1)); | ||
} | ||
value[vIndex] = tmpSum; | ||
vIndex ++; | ||
delete[] tmp; | ||
} else { | ||
// 继续递归,对下一个元素的sup[]赋值 | ||
subSet(arr, Sup,value, index+1); | ||
} | ||
// 递归退回,重置后等待下一个for循环使该递归层次的元素的sup取下一个值 | ||
// 并重复以上递归过程,相当于以该层递归所属元素开始,对后面的元素的sup[]依次取0/1 | ||
Sup[index] = -1; | ||
} | ||
} | ||
int main() { | ||
cin>>n; | ||
int *arr = new int[n]; | ||
int *value = new int[(int)(pow(2.0,n))]; | ||
for(int i=0;i<n;i++) { | ||
int tmp; | ||
cin>>tmp; | ||
arr[i] = tmp; | ||
} | ||
int *sup = new int[n]; | ||
subSet<int>(arr,sup,value, 0); | ||
int xorSum = 0; | ||
// 求异或(按位异或) | ||
for(int i=0;i<(int)(pow(2,n));i++) { | ||
if(i == 0) { | ||
xorSum = value[i]; | ||
} | ||
else { | ||
xorSum ^= value[i]; | ||
} | ||
} | ||
cout<<xorSum; | ||
delete[] arr; | ||
delete[] value; | ||
return 0; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// Created by 邵嘉明 on 2021/9/28. | ||
// | ||
#include <iostream> | ||
#include <vector> | ||
using namespace std; | ||
int n; | ||
|
||
template<class T> | ||
void subSet(T arr[], T Sup[], int index) { | ||
// arr: 待求子集的数组 | ||
// sup: 辅助数组,bitset | ||
// index: 当前求二进制数求到数组中那个数的索引 | ||
for(int i=0;i<=1;i++) { | ||
Sup[index] = i; | ||
if(index == n-1) { | ||
// 递归已到头,对任意元素,其sup[]均已赋值0/1,输出该子集 | ||
cout<<"( "; | ||
for(int j=0;j<n;j++) { | ||
if(Sup[j] == 1) { | ||
cout<<arr[j]<<" "; | ||
} | ||
} | ||
cout<<")\n"; | ||
} else { | ||
// 继续递归,对下一个元素的sup[]赋值 | ||
subSet(arr, Sup, index+1); | ||
} | ||
// 递归退回,重置后等待下一个for循环使该递归层次的元素的sup取下一个值 | ||
// 并重复以上递归过程,相当于以该层递归所属元素开始,对后面的元素的sup[]依次取0/1 | ||
Sup[index] = -1; | ||
} | ||
} | ||
int main() { | ||
cin>>n; | ||
int *arr = new int[n]; | ||
for(int i=0;i<n;i++) { | ||
int tmp; | ||
cin>>tmp; | ||
arr[i] = tmp; | ||
} | ||
int *sup = new int[n]; | ||
subSet<int>(arr,sup, 0); | ||
delete[] arr; | ||
return 0; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <iostream> | ||
using namespace std; | ||
int n; | ||
int vIndex = 0; | ||
template<class T> | ||
void Swap(T &a, T &b) { | ||
T tmp = a; | ||
a = b; | ||
b = tmp; | ||
} | ||
int factorial(int num) | ||
{ | ||
// 基本情况返回1; | ||
if (num == 0 || num == 1) { | ||
return 1; | ||
} else { | ||
int tmp = 1; | ||
for(int i=num;i>=1;i--) { | ||
tmp *= i; | ||
} | ||
return tmp; | ||
} | ||
} | ||
template<class T> | ||
void permutations(T list[],T value[], int k,int m) { | ||
// 生成list[k:m]的所有排列 | ||
// 排列的前缀为list[0:k-1],后缀为list[k:m] | ||
if(k == m) { | ||
// 此时,仅有前缀,仅有一个排列,即得到了"一个排列" | ||
/*for(int i=0;i<=m;i++) { | ||
cout<<list[i]; | ||
} | ||
cout<<endl;*/ | ||
int tmpValue = 0; | ||
for(int i=0;i<=m;i++) { | ||
tmpValue += (list[i] ^ (i+1)); | ||
} | ||
value[vIndex] = tmpValue; | ||
vIndex ++; | ||
} else { | ||
// list[k:m]有多于一个的排列,递归地(向后)生成这些排列,不断加长前缀,减短后缀 | ||
for(int i=k;i<=m;i++) { | ||
// 交换元素ek和ei | ||
Swap(list[k],list[i]); | ||
// 调用permutations计算ei*perm(Ei),最终开出n个分支,分别是第[0:n-1]个数为前缀,后面的数为后缀的排列 | ||
// 这n个分支再进行递归,最终求出各个排列 | ||
permutations(list,value,k+1,m); | ||
// 将list[k:m]恢复到第一个swap调用之前的状态,表明已经生成了第i个数为前缀的所有排列,已经递归跳回来 | ||
// 准备下一轮for循环时,再以下一个数(第i+1个数)为前缀,递归地生成排列 | ||
Swap(list[k],list[i]); | ||
} | ||
} | ||
} | ||
|
||
int main() { | ||
cin>>n; | ||
int *arr = new int[n]; | ||
int *value = new int[factorial(n)]; | ||
for(int i=0;i<n;i++) { | ||
int tmp; | ||
cin>>tmp; | ||
arr[i] = tmp; | ||
} | ||
permutations(arr,value, 0, n-1); | ||
// 求所有排列的价值的或 | ||
int orRes = 0; | ||
for(int i=0;i<vIndex;i++) { | ||
if(i == 0)orRes = value[i]; | ||
else orRes |= value[i]; | ||
} | ||
cout<<orRes; | ||
delete [] arr; | ||
delete [] value; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <iostream> | ||
#include <vector> | ||
using namespace std; | ||
int n; | ||
template<class T> | ||
void Swap(T &a, T &b) { | ||
T tmp = a; | ||
a = b; | ||
b = tmp; | ||
} | ||
template<class T> | ||
void permutations(T list[],int k,int m) { | ||
// 生成list[k:m]的所有排列 | ||
// 排列的前缀为list[0:k-1],后缀为list[k:m] | ||
if(k == m) { | ||
// 此时,仅有前缀,仅有一个排列,输出它 | ||
for(int i=0;i<=m;i++) { | ||
cout<<list[i]; | ||
} | ||
cout<<endl; | ||
} else { | ||
// list[k:m]有多于一个的排列,递归地(向后)生成这些排列,不断加长前缀,减短后缀 | ||
for(int i=k;i<=m;i++) { | ||
// 交换元素ek和ei | ||
Swap(list[k],list[i]); | ||
// 调用permutations计算ei*perm(Ei),最终开出n个分支,分别是第[0:n-1]个数为前缀,后面的数为后缀的排列 | ||
// 这n个分支再进行递归,最终求出各个排列 | ||
permutations(list,k+1,m); | ||
// 将list[k:m]恢复到第一个swap调用之前的状态,表明已经生成了第i个数为前缀的所有排列,已经递归跳回来 | ||
// 准备下一轮for循环时,再以下一个数(第i+1个数)为前缀,递归地生成排列 | ||
Swap(list[k],list[i]); | ||
} | ||
} | ||
} | ||
|
||
int main() { | ||
cin>>n; | ||
int *arr = new int[n]; | ||
for(int i=0;i<n;i++) { | ||
int tmp; | ||
cin>>tmp; | ||
arr[i] = tmp; | ||
} | ||
permutations(arr, 0, n-1); | ||
delete[] arr; | ||
return 0; | ||
} |
Oops, something went wrong.