oracle安装

linux无图形界面不太行(有一个教程https://blog.csdn.net/whbing1471/article/details/52087130 看起来还可以)


下载oracle包(百度网盘上有),两个zip用unzip命令解压

安装的时候用户不能是root,需要先创建用户oracle。之后sudo usermod -aG sudo oracle 添加到sudo权限的。

urllib代理

urllib代理查了好多都没查到……

1
2
3
4
request = Request(url, data=flac_data, headers={"Content-Type": "audio/x-flac; rate={}".format(audio_data.sample_rate)})
handler = urllib.request.ProxyHandler({"http": "127.0.0.1:1087"})
opener = urllib.request.build_opener(handler)
response = opener.open(request, timeout=self.operation_timeout)

Mac配语音识别库

pyaudio安装

Mac和python3.7在一起是不配用pyaudio的!多么痛的领悟!

所以安装python3.6!

brew install portaudio之后用pip安装pyaudio即可

swig安装

官网下载,执行configure、make、make install即可(我下载的是最新版本4.0.1)

pocketsphinx安装

直接pip3 install可能报错,所以需要用这个issue里面的方法安装:

https://github.com/bambocher/pocketsphinx-python/issues/28

也就是

Please try the following steps

  1. git clone –recursive https://github.com/bambocher/pocketsphinx-python
  2. cd pocketsphinx-python
  3. Edit file deps/sphinxbase/src/libsphinxad/ad_openal.c
  4. Change

#include <al.h>
#include <alc.h>

to

#include <OpenAL/al.h>
#include <OpenAL/alc.h>

  1. python setup.py install

相关使用

https://www.cnblogs.com/henjay724/p/9576670.html

leetcode-for-vs-code

直接安装Node js和leetcode这个插件,登录之后选择code now之后选择目录,即可。

在代码模板中可以准备一个headers.h并且把它的import放到// @lc code=start上面,把main放到// @lc code=end下面

插件的设置可以在这个位置找到:

插件设置位置

之后设置launch和tasks选项,我把我的拿过来:

launch.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"version": "0.2.0",
"configurations": [
{
"name": "(msvc) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/build/main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "msvc build"
}
]
}

tasks.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"version": "2.0.0",
"tasks": [
{
"label": "msvc build",
"type": "shell",
"command": "./build.bat",
"args": ["${workspaceRoot}","${fileBasename}","${fileBasenameNoExtension}"],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
}
]
}

另外,build.bat如下

1
2
3
4
5
6
7
8
@echo off
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
cd /d %1
mkdir build
set compilerflags=/Od /Zi /EHsc /Wall /std:c++14
set linkerflags=/Fe:%1/build/main.exe
cl.exe %compilerflags% %2 %linkerflags%
del %3.obj

每日leetcode-149

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.

Example 1:

Input: [[1,1],[2,2],[3,3]]
Output: 3
Explanation:
^
|
| o
| o
| o
+————->
0 1 2 3 4
Example 2:

Input: [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
Output: 4
Explanation:
^
|
| o
| o o
| o
| o o
+——————->
0 1 2 3 4 5 6
NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.

这道题直接用最简单的$n^3$的遍历就可以做,但是有几点没有注意:

  1. 固定第一个、第二个点,确定其他点是不是共线的时候,需要注意前两个点不能相同!
  2. 可能所有点都是相同的!也就是两个点、三个点的时候,都是相同的点!
  3. 不能在相同的时候直接判断下一个是否相同然后累计连续的相同的点的个数!因为可能会前面也有别的相同的点!所以不要直接用计数变量的方式处理这种情况,要单独写一个记录当前相同点数目的!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Solution {
public:
bool isSameLine(vector<int>& a, vector<int>& b, vector<int>& c) {
// k = (a[1] - b[1]) / (a[0] - b[0]) = (a[1] - c[1]) / (a[0] - c[0])
return (long long)(a[0] - b[0]) * (long long)(a[1] - c[1]) == (long long)(a[1] - b[1]) * (long long)(a[0] - c[0]);
// 都不为0时,没有问题;为0时,分别是三个横坐标/纵坐标相等或者两个点重合
}

int maxPoints(vector<vector<int>>& points) {
int len = points.size();
if (len == 0) {
return 0;
}
if (len == 1) {
return 1;
}
int ans = 2;
int count;
for (int i = 0; i < len - 2; i++) {
int same_points = 0;
for (int j = i + 1; j < len; j++) { // 可能有三个点相同的情况
if (points[i] == points[j]) {
same_points++;
continue;
}
count = 2;
for (int k = j + 1; k < len; k++) {
if (isSameLine(points[i], points[j], points[k])) {
count++;
}
}
if (count + same_points > ans) {
ans = count + same_points;
}
}
if (1 + same_points > ans) {
ans = 1 + same_points;
}
}

return ans;
}
};

每日leetcode-185

185. Department Top Three Salaries

The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id.

+—-+——-+——–+————–+
| Id | Name | Salary | DepartmentId |
+—-+——-+——–+————–+
| 1 | Joe | 85000 | 1 |
| 2 | Henry | 80000 | 2 |
| 3 | Sam | 60000 | 2 |
| 4 | Max | 90000 | 1 |
| 5 | Janet | 69000 | 1 |
| 6 | Randy | 85000 | 1 |
| 7 | Will | 70000 | 1 |
+—-+——-+——–+————–+
The Department table holds all departments of the company.

+—-+———-+
| Id | Name |
+—-+———-+
| 1 | IT |
| 2 | Sales |
+—-+———-+
Write a SQL query to find employees who earn the top three salaries in each of the department. For the above tables, your SQL query should return the following rows (order of rows does not matter).

+————+———-+——–+
| Department | Employee | Salary |
+————+———-+——–+
| IT | Max | 90000 |
| IT | Randy | 85000 |
| IT | Joe | 85000 |
| IT | Will | 70000 |
| Sales | Henry | 80000 |
| Sales | Sam | 60000 |
+————+———-+——–+
Explanation:

In IT department, Max earns the highest salary, both Randy and Joe earn the second highest salary, and Will earns the third highest salary. There are only two employees in the Sales department, Henry earns the highest salary while Sam earns the second highest salary.

这个里面最重要的是怎么能够选出满足条件top three salaries in each of the department的。这种前几个的问题就用选择之后count比较的方法就可以,其实就是说每个选中的人,和他同一部门并且比他工资高的工资(要去重)小于3个。

所以:

1
2
3
4
5
6
# Write your MySQL query statement below
select t2.Name as Department, t1.Name as Employee, Salary
from Employee t1 join Department t2 on t1.DepartmentId = t2.Id
where
(select count(distinct e.Salary) from Employee e where e.Salary > t1.Salary and e.DepartmentId = t1.DepartmentId) < 3
order by Department, Salary desc;

每日leetcode-174

174. Dungeon Game

The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight his way through the dungeon to rescue the princess.

The knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies immediately.

Some of the rooms are guarded by demons, so the knight loses health (negative integers) upon entering these rooms; other rooms are either empty (0’s) or contain magic orbs that increase the knight’s health (positive integers).

In order to reach the princess as quickly as possible, the knight decides to move only rightward or downward in each step.

Write a function to determine the knight’s minimum initial health so that he is able to rescue the princess.

就是从左上到右下,HP会加上格子里面的数,HP不能<=0,求初始HP最少是多少。

刚开始想要从左上到右下正常dp,记录一下当前的 HP减少量 和 HP最优路径中临界值,但是如果:

  • 到同一个格子的两条路,一条当前HP减少量最少,另外一条HP最优路径中临界值更少,那应该选哪一条?怎么更新?

所以看了网上的解释,直接从结果往回走进行dp即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Solution {
public:
int myMin(int a, int b) {
return a < b ? a : b;
}

int myMax(int a, int b) {
return a > b ? a : b;
}

int calculateMinimumHP(vector<vector<int>>& dungeon) {
int h = dungeon.size();
if (h == 0) {
return 1;
}
int w = dungeon[0].size();
if (w == 0) {
return 1;
}
vector<vector<int>> data(h, vector<int>(w, 0));
data[h - 1][w - 1] = myMax(1, 1 - dungeon[h - 1][w - 1]);
int i, j;
i = h - 1;
for (j = w - 2; j >= 0; j--) {
data[i][j] = myMax(1, data[i][j + 1] - dungeon[i][j]);
}
j = w - 1;
for (i = h - 2; i >= 0; i--) {
data[i][j] = myMax(1, data[i + 1][j] - dungeon[i][j]);
}
for (i = h - 2; i >= 0; i--) {
for (j = w - 2; j >= 0; j--) {
data[i][j] = myMin(myMax(1, data[i][j + 1] - dungeon[i][j]), myMax(1, data[i + 1][j] - dungeon[i][j]));
}
}
return data[0][0];
}
};