From 9af6968d86d8912acbcf9da094616fab43071f16 Mon Sep 17 00:00:00 2001 From: yewuya <32785496+yewuya0206@users.noreply.github.com> Date: Tue, 18 May 2021 16:46:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B9=B1=E4=B8=83=E5=85=AB?= =?UTF-8?q?=E7=B3=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pico 配置.md | 2 + ubuntu 下vnc的使用.md | 19 ++ 出题.md | 441 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 417 insertions(+), 45 deletions(-) diff --git a/Pico 配置.md b/Pico 配置.md index d6baec5..b155a9a 100644 --- a/Pico 配置.md +++ b/Pico 配置.md @@ -4,6 +4,8 @@ LTAI5tDmuBc9sA3CDso9bwe3 MzzUtOfOKx7CK3rFoSckNvujkQGBF3 +MzzUtOfOKx7CK3rFoSckNvujkQGBF3 + yewuyadeimagewall oss-cn-hangzhou \ No newline at end of file diff --git a/ubuntu 下vnc的使用.md b/ubuntu 下vnc的使用.md index f8c1d00..1ad2d87 100644 --- a/ubuntu 下vnc的使用.md +++ b/ubuntu 下vnc的使用.md @@ -10,6 +10,25 @@ vnc启动 vncserver -geometry 1920x1080 ``` + + +```sh +#!/bin/sh +unset SESSION_MANAGER +unset DBUS_SESSION_BUS_ADDRESS +startxfce4 & +[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup +[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources +xsetroot -solid grey +vncconfig -iconic & +``` + + + + + + + vnc连接 * Mac diff --git a/出题.md b/出题.md index 8123594..104af55 100644 --- a/出题.md +++ b/出题.md @@ -1,47 +1,10 @@ # 面试题 -* 在ROS中,通过捕捉按键输入完成飞机的模式切换,该方式比较适合多机一键起飞或者其他模式切换操作。 - 简单说明:采用的是C++标准库提供的cin函数,但是这种方式为阻塞等待键盘按下,所以需要采用多线程或者多进程的方式,又采用了的是共享变量(标志位)的想法,故在一个进程中采用多线程即可。下面的示例给出一个简单的实现模板。在ROS中可以直接编译执行,在单C++函数中,需要在g++ -lpthread完成编译。join的作用为主函数运行结束后,子线程仍然可以一直运行,而不是一起结束 +## 1 -```c++ -#include -#include +### 题目 -int count = 0; -void thr_fun1(void) -{ -    while(1) -    { -        if(count == 1) -        { -            std::cout<<"here!"<>str; -        if(str=="arm") -        { -            std::cout<<"quadrotor armed!"< + +int fun(int m,int n) //m个苹果放在n个盘子***有几种方法 +{ + if(m==0||n==1) //因为我们总是让m>=n来求解的,所以m-n>=0,所以让m=0时候结束,如果改为m=1, + return 1; //则可能出现m-n=0的情况从而不能得到正确解 + if(n>m) + return fun(m,m); + else + return fun(m,n-1)+fun(m-n,n); +} + +int main() +{ + int T,m,n; + scanf("%d",&T); + while(T--) + { + scanf("%d%d",&m,&n); + printf("%d\n",fun(m,n)); + } +} +``` + +## 6 + +### 题目 + +给定一个经过编码的字符串,返回它解码后的字符串。 + +编码规则为: k[encoded_string],表示其中方括号内部的 encoded_string 正好重复 k 次。注意 k 保证为正整数。 + +你可以认为输入字符串总是有效的;输入字符串中没有额外的空格,且输入的方括号总是符合格式要求的。 + +此外,你可以认为原始数据不包含数字,所有的数字只表示重复的次数 k ,例如不会出现像 3a 或 2[4] 的输入。 + +示例 1: + +输入: + +``` +s = "3[a]2[bc]" +``` + +输出: + +``` +aaabcbc +``` + +输入: + +``` +s = "3[a2[c]]" +``` +输出: + +``` +accaccacc +``` + +初始代码 + +```c++ +class Solution { +public: + string decodeString(string s) { + + } +}; +``` + +### 答案 + +```c++ +class Solution { +public: + string getDigits(string &s, size_t &ptr) { + string ret = ""; + while (isdigit(s[ptr])) { + ret.push_back(s[ptr++]); + } + return ret; + } + + string getString(vector &v) { + string ret; + for (const auto &s: v) { + ret += s; + } + return ret; + } + + string decodeString(string s) { + vector stk; + size_t ptr = 0; + + while (ptr < s.size()) { + char cur = s[ptr]; + if (isdigit(cur)) { + // 获取一个数字并进栈 + string digits = getDigits(s, ptr); + stk.push_back(digits); + } else if (isalpha(cur) || cur == '[') { + // 获取一个字母并进栈 + stk.push_back(string(1, s[ptr++])); + } else { + ++ptr; + vector sub; + while (stk.back() != "[") { + sub.push_back(stk.back()); + stk.pop_back(); + } + reverse(sub.begin(), sub.end()); + // 左括号出栈 + stk.pop_back(); + // 此时栈顶为当前 sub 对应的字符串应该出现的次数 + int repTime = stoi(stk.back()); + stk.pop_back(); + string t, o = getString(sub); + // 构造字符串 + while (repTime--) t += o; + // 将构造好的字符串入栈 + stk.push_back(t); + } + } + + return getString(stk); + } +}; +``` + +## 7 + +### 题目 + +输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字。 + +输入: + +``` +matrix = [[1,2,3],[4,5,6],[7,8,9]] +``` + + +输出: + +``` +[1,2,3,6,9,8,7,4,5] +``` + +输入: + +``` +matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] +``` + +输出: + +``` +[1,2,3,4,8,12,11,10,9,5,6,7] +``` + +初始代码 + +```c++ +class Solution { +public: + vector spiralOrder(vector>& matrix) { + + } +}; +``` + +### 答案 + +```c++ +class Solution { +private: + static constexpr int directions[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; +public: + vector spiralOrder(vector>& matrix) { + if (matrix.size() == 0 || matrix[0].size() == 0) { + return {}; + } + + int rows = matrix.size(), columns = matrix[0].size(); + vector> visited(rows, vector(columns)); + int total = rows * columns; + vector order(total); + + int row = 0, column = 0; + int directionIndex = 0; + for (int i = 0; i < total; i++) { + order[i] = matrix[row][column]; + visited[row][column] = true; + int nextRow = row + directions[directionIndex][0], nextColumn = column + directions[directionIndex][1]; + if (nextRow < 0 || nextRow >= rows || nextColumn < 0 || nextColumn >= columns || visited[nextRow][nextColumn]) { + directionIndex = (directionIndex + 1) % 4; + } + row += directions[directionIndex][0]; + column += directions[directionIndex][1]; + } + return order; + } +}; +``` + +## 8 + +### 题目 + +static的用法(定义和用途) + +### 答案 + +1)用static修饰局部变量:使其变为静态存储方式(静态数据区),那么这个局部变量在函数执行完成之后不会被释放,而是继续保留在内存中。 + +2)用static修饰全局变量:使其只在本文件内部有效,而其他文件不可连接或引用该变量。 + +3)用static修饰函数:对函数的连接方式产生影响,使得函数只在本文件内部有效,对其他文件是不可见的(这一点在大工程中很重要很重要,避免很多麻烦,很常见)。这样的函数又叫作静态函数。使用静态函数的好处是,不用担心与其他文件的同名函数产生干扰,另外也是对函数本身的一种保护机制。 + +## 9 + +### 题目 + +const的用法(定义和用途) + +### 答案 + +const主要用来修饰变量、函数形参和类成员函数: + +1)用const修饰常量:定义时就初始化,以后不能更改。 + +2)用const修饰形参:func(const int a){};该形参在函数里不能改变。 + +3)用const修饰类成员函数:该函数对成员变量只能进行只读操作,就是const类成员函数是不能修改成员变量的数值的。 + +被const修饰的东西都受到强制保护,可以预防意外的变动,能提高程序的健壮性。 + +## 10 + +### 题目 + +一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 “Start” )。 + +机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为 “Finish” )。 + +问总共有多少条不同的路径? + +![img](https://yewuyadeimagewall.oss-cn-hangzhou.aliyuncs.com/robot_maze.png) + +``` +输入:m = 3, n = 7 +输出:28 +``` + +初始代码 + +```c++ +class Solution { +public: + int uniquePaths(int m, int n) { + + } +}; +``` + +### 答案 + +```c++ +class Solution { +public: + int uniquePaths(int m, int n) { + vector> f(m, vector(n)); + for (int i = 0; i < m; ++i) { + f[i][0] = 1; + } + for (int j = 0; j < n; ++j) { + f[0][j] = 1; + } + for (int i = 1; i < m; ++i) { + for (int j = 1; j < n; ++j) { + f[i][j] = f[i - 1][j] + f[i][j - 1]; + } + } + return f[m - 1][n - 1]; + } +}; +``` + + +