自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(20)
  • 收藏
  • 关注

原创 1098 Insertion or Heap Sort (25 分)

#include <iostream>#include <vector>#include <algorithm>using namespace std;#define PARANT(x) (((x)-1) >> 1)#define LCHILD(x) (((x) << 1) + 1)#define RCHILD(x) (((x) + 1) << 1)#define INHEAP(n, x) (((x) >= 0) .

2021-08-21 23:46:48 164

原创 1066 Root of AVL Tree (25 分)

#include <iostream>#include <algorithm>using namespace std;typedef struct TreeNode{ int val, height; TreeNode *left, *right;} TreeNode;TreeNode *root = nullptr;int getheight(TreeNode *node){ if (node == nullptr) re.

2021-08-18 17:10:27 139

原创 1053 Path of Equal Weight (30 分)

#include <vector>#include <stack>#include <iostream>#include <algorithm>using namespace std;typedef struct TreeNode{ int weight, K=0, child[99];} TreeNode;int N, M, S;TreeNode node[100];vector<vector<int>&...

2021-08-17 15:17:13 135

原创 二叉树中序遍历

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} *.

2021-08-15 11:37:08 90

原创 二叉树后序遍历

class Solution{public: vector<int> v; stack<TreeNode *> s; TreeNode *cur ; void findnext() { while (true) { while (cur->left != nullptr) { cur = cur->left;.

2021-08-15 11:36:16 47

原创 二叉树先序遍历

非递归栈1:采用左右子节点入栈/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), rig

2021-08-15 10:13:35 44

原创 1103 Integer Factorization (30 分)

#include <bits/stdc++.h>using namespace std;//FILE *p = fopen("file.txt", "w");int N, K, P, maxsum = 0, mintop = 20;stack<int> maxs, s;stack<int> tmps ,tmpmaxs;int up;void dfs(int cnt, int n, int sum, int ans){ if (n != 0) .

2021-08-13 22:22:11 65

原创 1093 Count PAT‘s (25 分)简单做法

1093 Count PAT's (25 分)The stringAPPAPTcontains twoPAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.Now given any string, you are suppo...

2021-08-06 14:48:43 69

原创 ping通www.baidu.com的完整过程。

ping通www.baidu.com的完整过程。用tcpdump抓包和wireshark软件分析抓到的包,通过抓到的包、自己的知识储备,结合网络知识分析ping程序的网络完整过程。1、主机查找本地系统Hosts文件的DNS缓存,如果存在www.baidu.com对应的IP,则获取IP;2、若本地系统没有对应IP,主机操作系统生成一个DNS查询报文,将字符串www.baidu.com放入DNS报文段中。该DNS报文段被放置于53号(DNS服务器)目的端口的UDP报文段。该UDP报文则被放入

2021-07-08 23:17:39 25892 5

原创 进制相互转换

十进制转换为其他进制:int z[40],num=0;//z[40]中存放转换之后的进制数,num存放结果位数do{ z[num++]=n%c; n/=c;}while(n!=0);其他进制转换为十进制:int y=0,product=1;while(x!=0){ y=y+(x%10)*product; x/=10; protected*=P;}...

2021-07-07 22:38:12 81

原创 1003 Emergency(25分)

#include<iostream>#include<vector>const int INT_MAX = 2147483647;typedef enum { UNDISCOVERED, VISITED }VStatus;//顶点状态,未访问和已访问template<typename Tv> struct Vertex {//城市 Tv data;//消防队的数量,即顶点的数据 VStatus status;//顶点状态 Verte...

2021-02-18 23:11:58 82

原创 良好的C++编程风格

良好的C++编程风格非常重要Google开源C++风格指南

2020-11-22 23:34:45 130

原创 KMP算法重温——改进型串的模式匹配算法

KMP算法重温——改进型串的模式匹配算法1.暴力法求子串位置的定位函数。暴力算法的思想是遍历主串中的字符,看是否和子串中的首字符一直,若相等,则继续比较主串中和子串匹配的字母的下一个字符,看是否与子串中的下一个字符相等,若不想等,则比较主串中的下一个字母与子串中的首字符比较,直到找到与子串匹配的主串序列或到主串末尾2.暴力法弊端在最坏情况下,时间复杂度为O(n*m),指向主串的指针回溯过程中,可能出现重复,执行一些明显不会匹配的过程3.改进型算法(KMP算法)此算法完成串的模式匹配操

2020-10-18 14:00:20 155

原创 C++小程序崩溃了

这个是为什么?

2020-10-10 16:44:12 205

原创 C++小程序崩溃

#include <iostream>using std::cin; using std::cout; using std::endl;#include <string>using std::string;#include <cstddef>using std::size_t;int main(){ const string hexdigits = "0123456789ABCDEF"; // possible hex digits co...

2020-09-16 13:55:48 3278

原创 3.2③文本格式化

3.2③文本格式化(一) [问题描述]输入文件中含有待格式化(或称为待排版)的文本,它由多行的文字组成,例如一篇英文文章。每一行由一系列被一个或多个空格符所隔开的字组成,任何完整的字都没有被分割在两行(每行最后一个字与下一行的第一个字之间在逻辑上应该由空格分开),每行字符数不超过80。除了上述文本类字符之外,还存在着起控制作用的字符:符号“@”指示它后面的正文在格式化时应另起一段排放,即空一行,并在段首缩入8个字符位置。“@”自成一个字。一个文本格式化程序可以处理上述输入文件,按照用户指定的版面规格.

2020-05-14 17:17:52 2683 11

原创 ◆5.2③哈夫曼编/译码器

**◆5.2③哈夫曼编/译码器**[问题描述]利用哈夫曼编码进行通信可以大大提高信道利用率,缩短信息传输时间,降低传输成本。但是,这要求在发送端通过一个编码系统对待传数据预先编码,在接收端将传来的数据进行译码(复原)。对于双工信道(即可以双向传输信息的信道),每端都需要一个完整的编/译码系统。试为这样的信息收发站写一个哈夫曼码的编/译码系统。[基本要求]一个完整的系统应具有以下功能:(1) I:初始化(Initialization)。从终端读入字符集大小n,以及n个字符和n个权值, .

2020-05-14 17:06:07 2818 3

原创 文件fread函数巧妙用法

//求得文件的大小 fseek(fp, 0, SEEK_END); size = ftell(fp); rewind(fp); //申请一块能装下整个文件的空间 ar = (char*)malloc(sizeof(char)*size); //读文件 fread(ar,1,size,fp);//每次读一...

2020-05-07 13:56:03 534

原创 leetcode 错误runtime error: load of null pointer of type 'int *' (__Serializer__.c)

*runtime error: load of null pointer of type 'int ’ (Serializer.c)错误解决leetcode第102题层序遍历二叉树笔者写时发现忘了算空树的情况于是就在levelorder函数下第一行加上if(root==NULL) return NULL;于是,再次提交时奇怪的事情发生了执行都过不了然后去查,就发现了,leetc...

2020-04-25 20:02:30 8747 3

原创 结构体变量中的初始化问题,malloc函数在子函数中的应用

结构体申请变量后,一定要全部初始化,不然在某些IDE上可能出现bug;`仔细看下面的,错误一大堆一大堆#include<string.h>#include<malloc.h> #include<stdio.h> #include<stdlib.h> struct TreeNode{ int val; struct TreeNode...

2020-04-25 19:47:52 825

空空如也

空空如也

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

TA关注的人

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