
算法
PAT算法总结
Uranus_A
这个作者很懒,什么都没留下…
展开
-
求解最大公因数+求解最小公倍数
#include<iostream> using namespace std; int gcd(int a,int b) //最大公约数 { return !b?a:gcd(b,a%b); } int lcm(int a,int b) //最小公倍数 { return a/gcd(a,b)*b/gcd(a,b); } int main() { return 0; }原创 2022-02-10 14:58:22 · 419 阅读 · 0 评论 -
1102 Invert a Binary Tree (25 分)-------如何反转二叉树+二叉树的层序和中序遍历
#include<iostream> #include<queue> using namespace std; struct Node { int lchild; int rchild; }node[110]; bool isnotroot[110]={false}; int n,num=0; void print(int id) { cout<<id; num++; if(num!=n) cout<&原创 2022-02-10 14:53:24 · 407 阅读 · 0 评论 -
1053 Path of Equal Weight (30 分)-------带权树的DFS
#include<iostream> #include<vector> #include<algorithm> using namespace std; const int maxn=110; struct Node { int weight; vector<int> child; }node[maxn]; bool cmp(int a,int b) { return node[a].weight>node[b].weight原创 2022-02-09 16:28:54 · 345 阅读 · 0 评论 -
1020 Tree Traversals (25 分)/中序遍历+后序遍历转为层次遍历
#include<iostream> #include<queue> #include<algorithm> #include<stdio.h> using namespace std; struct node { int data; node* lchild; node* rchild; }; const int maxn=50; int n,pre[maxn],post[maxn],in[maxn]; node* create(原创 2022-02-09 11:29:00 · 95 阅读 · 0 评论 -
全排序和N皇后
```cpp #include<iostream> #include<cstdio> using namespace std; const int maxn=11; int n,P[maxn],hashTable[maxn]={0}; //P为当前排列,hashTable记录整数x是否已在P中 //当前处理的事排列的第index位 void generateP(int index) { if(index==n+1) //递归边界 此时已经处理完1-N位 { .原创 2022-01-17 15:12:46 · 81 阅读 · 0 评论