自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 【荣耀机试题】爬楼梯-可后退

题目描述:给出n阶台阶,每次只可以前进一步或者两步,中途有一次机会可以后退一步,这次机会也可以不使用,到达最后一个台阶一共有多少种走法?题目分析 :本题是在原本经典跳楼梯上增加了可以有一次回退的条件。原本的题怎么做呢?#include <iostream>using namespace std;const int N = 1e3+10;int dp[N];int main(){ int n; cin>>n; dp[0] = 1;

2022-04-24 22:48:52 815

原创 heap for go

func heapSort(arr []int) []int{ CreateHeap(arr) for i:=0;i<len(arr);i++{ arr[0],arr[len(arr)-1-i] = arr[len(arr)-1-i],arr[0] downAdjust(arr,0,len(arr)-1-i) } return arr}func CreateHeap(arr []int){ for i:=len(arr)/2;i>=0;i--{ downAdjust.

2021-09-03 12:03:36 91

原创 apue 4.6 习题 (cp1)

#include <apue.h>#include <fcntl.h>/* 4.6*/int my_cp(char *dest,char *src){ int s_field,d_field; if ((s_field = open(src, O_RDONLY))<0){ err_sys("open source file error!"); exit(0); } struct stat s; .

2021-06-15 15:04:05 137

原创 apue 3.2 dup2实现

/* 3,2*/int my_dup2(int fd1,int fd2){ if (fd2<0||fd2 > OPENMAX){ err_sys("wrong input newfd"); exit(0); } if (fd1==fd2){ return fd2; } int min = dup(fd1);//寻找当前最小的文件表项 if (min==-1){ err_.

2021-06-10 14:03:41 82

原创 1059 Prime Factors (25 分) DFS实现

1059Prime Factors(25 分)Given any positive integerN, you are supposed to find all of its prime factors, and write them in the formatN=p​1​​​k​1​​​​×p​2​​​k​2​​​​×⋯×p​m​​​k​m​​​​.Input Specifi...

2019-02-28 21:27:02 132

原创 1145 Hashing - Average Search Time (25 分)

The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys from the table and output the average sea...

2019-02-26 16:05:23 106

原创 Huffman树编码 DFS实现

通过写这个编码和huffman树的构建,让我对huffman tree 有了更深的理解:1:首先huffman是经过n-1次迭代之后生成的树,所以如果开始的节点有n个的话,那麽生成之后的的树的节点个数是2*n-12:编码的话可以用DFS处理;3:树的节点新加了一个parents值,让我学到了一种新的写法。//在挑选最小值的时候需要#include&lt;iostream&gt;...

2019-02-24 22:00:24 241

原创 AVL树操作

#include &lt;iostream&gt;#include &lt;cstdio&gt;#include &lt;algorithm&gt;#include &lt;cstring&gt;#include &lt;vector&gt;#include &lt;stack&gt;using namespace std;struct node{ int val; ...

2019-02-23 22:13:37 147

原创 判断是否是完全二叉树的方法

1:填数组二叉树可以这样表示根节点是 i ,那麽左孩子是 2 * i ,右孩子是 2 * i + 1,根据这个关系可已经进行填表处理。struct node{ int val; node *left,*right;};int n;//树节点的数量int node[2^n];int finindex=0;void fill(node *node,int index...

2019-02-23 20:46:49 302

原创 1060 Are They Equal (25 分)

1060 Are They Equal (25 分)If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123×10​5​​ with simple chopping. No...

2019-02-23 18:51:03 122

原创 1053 Path of Equal Weight (30 分)

Given a non-empty tree with root R, and with weight W​i​​ assigned to each tree node T​i​​. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path fro...

2019-02-23 11:29:40 184

转载 转载 lower_bound( )和upper_bound( )

lower_bound( )和upper_bound( )都是利用二分查找的方法在一个排好序的数组中进行查找的。在从小到大的排序数组中,lower_bound( begin,end,num):从数组的begin位置到end-1位置二分查找第一个大于或等于num的数字,找到返回该数字的地址,不存在则返回end。通过返回的地址减去起始地址begin,得到找到数字在数组中的下标。upper_...

2019-02-22 10:35:13 66

原创 二叉树中序遍历 先序遍历 构建 和 中序 后序建立 构建 和 先序 后序构建的多种情况

1.先序 中序 构建e.g.:先序:4 1 3 2 6 5 7中序:1 2 3 4 5 6 7构建代码:struct node{ int data; node *left,*right;};vector&lt;int&gt; pre,in;//preL,inL 是前序和中序的左边界 preR , inR 同理node *create(int...

2019-02-20 23:16:54 101

原创 求解无向图的连通分量个数方法

1:DFS#define N 10000 //图中点的个数int graph[N][N];// 0 表示没有边 1 表示有边bool visited[N]={false};void DFS(int root){ visited[root]=true; for(int i=0;i&lt;N;i++){ if(visited[i]==false&amp;&a...

2019-02-20 21:05:54 7719

原创 PAT dump整理

1.什么是堆?堆是一棵完全二叉树。每一个节点的值都不小于(或大于)其子节点的值。2.建堆处理:向下调整:int *heap;//最大堆//low是数组欲要调整节点的位置,high是堆最高节点的坐标void downAdjust(){ int i=low,j=i*2; while(j&lt;=high){ if(j+1&lt;=hi...

2019-02-18 15:33:23 97

原创 1079 Total Sales of Supply Chain (25 分)BFS解法

1079 Total Sales of Supply Chain (25 分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starti...

2019-01-31 22:20:32 150

原创 PAT甲级 1001. A+B Format (20) 递归解法

1001 A+B Format (20 分)Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Spe...

2019-01-14 19:37:17 132

原创 Java总结:Java 流(Stream)、文件(File)和IO

java.io 包几乎包含了所有操作输入、输出需要的类。所有这些流类代表了输入源和输出目标。输入输出流简介一个流被定义为一个数据序列。输入流用于从源读取数据,输出流用于向目标写数据。下图是一个描述输入流和输出流的类层次图:在java.io包中操作文件内容的主要有两大类:字节流、字符流,两类都分为输入和输出操作。在字节流中输出数据主要是使用OutputStream完成,输入使的是InputStrea...

2018-06-14 18:58:35 142

转载 JVM中gc快速解读GC日志

文中将介绍GC日志的输出格式, 以及如何解读GC日志, 从中提取有用的信息。我们通过 -XX:+UseSerialGC 选项,指定JVM使用串行垃圾收集器, 并使用下面的启动参数让 JVM 打印出详细的GC日志:-XX:+PrintGCDetails-XX:+PrintGCDateStamps-XX:+PrintGCTimeStamps      这样配置以后,发生GC时输出的日志就类似于下面这种...

2018-06-14 18:57:36 213

空空如也

空空如也

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

TA关注的人

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