自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(7)
  • 问答 (1)
  • 收藏
  • 关注

原创 【算法导论】找第k小数

输入数组和k,返回第k小数。input:3 2 1 5 4 6 23output:3import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); String[] arr = str.s

2022-04-26 20:07:18 198

原创 kruskal算法的并查集 村庄是否连通

#include<iostream>using namespace std;int getParent(int v, int* p){ int t = v; while (p[t] > -1) { t = p[t]; } return t;}int main(){ int n, m; cin >> n >> m; int* p = new int[n]; for (int i = 0; i < n; i++)//初...

2021-11-24 19:04:47 693

原创 判断是否为堆-堆整理

#include<iostream>using namespace std;int tree[100000];int n;bool is_maxHeap(){ for (int i = 1; i <= n; i++) { int left = 2 * i; int right = 2 * i + 1; if (right <= n && tree[i] < tree[right])//右孩子存在并且大于本身 ...

2021-11-04 10:10:14 1181

原创 已知完全二叉树的先序遍历求后序遍历

#include<iostream>#include<string>using namespace std;string pre, tree, pos;int index = 0;void getTree(int x) //获取完全二叉树{ if (x > pre.size()) return; tree[x] = pre[index++]; getTree(x*2); getTree(x*2 + 1);}void getPo...

2021-11-03 16:52:49 590

原创 旋转的矩阵 顺时针逆时针打印C++

#include <iostream>#include<vector>using namespace std;int main(){ int cal = 1;//记录第几圈 奇数就是顺指针 偶数就是逆时针 vector<vector<int>>V;//V是二维数组 int row, col; cin >> row >> col; for (int i = 0; i < row; i++) { ...

2021-10-20 17:51:59 663

原创 KMP算法根据next数组推导模式字符串

#include<iostream>using namespace std;int main(){ int begin, end, len; cin >> begin >> end >> len; int* p = new int[len]; int* pNext = new int[len]; p[0] = begin; p[len - 1] = end; int val; for (int i = 0; i < le...

2021-10-13 23:48:45 658 1

原创 约瑟夫环queue队列实现循环 报数问题

#include<iostream>#include<queue>using namespace std;int main(){ queue<int>q; int n; cin >> n; for (int i = 1; i <= n; i++) { q.push(i); } int cal = 1; while (!q.empty()) { if (cal == 3) { q.pop();...

2021-10-12 22:42:29 221

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除