遍历算法手稿

1.中序后序求先序

已知二叉树后序遍历序列是dabec,中序遍历序列是debac,它的前序遍历序列是

2.先序中序求后序

已知一棵二叉树前序遍历和中序遍历分别为 ABDEGCFH 和 DBGEACHF,

前序中序与后序中序求二叉树的区别是,前序中序根节点在前序的从前往后-》找

​ 后序中序根节点在后序的从后往前《-找

八种排序算法

1.直接插入排序

经常碰到这样一类排序问题:把新的数据插入到已经排好的数据列中。

将第一个数和第二个数排序,然后构成一个有序序列

将第三个数插入进去,构成一个新的有序序列。

对第四个数、第五个数……直到最后一个数,重复第二步。

如何写成代码:

首先设定插入次数,即循环次数,for(int i=1;i<length;i++),1个数的那次不用插入。

设定插入数和得到已经排好序列的最后一个数的位数。insertNum和j=i-1。

从最后一个数开始向前循环,如果插入数小于当前数,就将当前数向后移动一位。

将当前数放置到空着的位置,即j+1。

代码实现如下:

或者内部是2个for形式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public static void insertSort(int[] a){
if(a.length>1){
int insertNum;
//下标0的默认是有序,后面的都是要插入的数
for(int i=1;i<a.length;i++){
insertNum = a[i];
//i-1个都是有序的
int j=i-1;
for(;j>=0;j--){
//待插的数比前面小,就后一位
if(insertNum<a[j]){
a[j+1]=a[j];
}else{
//否则停止移动
break;
}
}

a[j+1]=insertNum;
}
}

}

2.希尔排序

对于直接插入排序问题,数据量巨大时。

将数的个数设为n,取奇数k=n/2,将下标差值为k的书分为一组,构成有序序列。

再取k=k/2 ,将下标差值为k的书分为一组,构成有序序列。

重复第二步,直到k=1执行简单插入排序。

如何写成代码:

首先确定分的组数。

然后对组中元素进行插入排序。

然后将length/2,重复1,2步,直到length=0为止。

注意:第一趟32,23,5一组 和 43,13一组,组内直接插入排序

代码实现如下:

或者

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
public static void shellSort(int[] a){
if(a.length>1){
int len=a.length;
while(len>0){
len/=2;
for(int i=0;i<len;i++){//分的组
for(int j=i+len;j<a.length;j+=len){//组中的元素,除了第一个元素
//组内直接插入排序
int t=j-len; //组内第一个元素默认有序
int insertNum=a[j];
for(;t>=0;t-=len){
//待插的数比前面小,就后一位
if(insertNum<a[t]){
a[t+len]=a[t];
}else{
//否则停止移动
break;
}
}

a[t+len]=insertNum;

}
}
// for(int a1 :a)
// System.out.print(a1+"-");
// System.out.println();
}
}
}

3.简单选择排序

常用于取序列中最大最小的几个数时。

(如果每次比较都交换,那么就是交换排序;如果每次比较完一个循环再交换,就是简单选择排序。)

遍历整个序列,将最小的数放在最前面。

遍历剩下的序列,将最小的数放在最前面。

重复第二步,直到只剩下一个数。

如何写成代码:

首先确定循环次数,并且记住当前数字和当前位置。

将当前位置后面所有的数与当前数字进行对比,小数赋值给key,并记住小数的位置。

比对完成后,将最小的值与第一个数的值交换。

重复2、3步。

代码实现如下:

4.堆排序

对简单选择排序的优化。

将序列构建成大顶堆。

将根节点与最后一个节点交换,然后断开最后一个节点。

重复第一、二步,直到所有节点断开。

代码实现如下:

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
44
45
46
47
48
49
50
public  void heapSort(int[] a){
System.out.println("开始排序");
int arrayLength=a.length;
//循环建堆
for(int i=0;i<arrayLength-1;i++){
//建堆

buildMaxHeap(a,arrayLength-1-i);
//交换堆顶和最后一个元素
swap(a,0,arrayLength-1-i);
System.out.println(Arrays.toString(a));
}
}
private void swap(int[] data, int i, int j) {
// TODO Auto-generated method stub
int tmp=data[i];
data[i]=data[j];
data[j]=tmp;
}
//对data数组从0到lastIndex建大顶堆
private void buildMaxHeap(int[] data, int lastIndex) {
// TODO Auto-generated method stub
//从lastIndex处节点(最后一个节点)的父节点开始
for(int i=(lastIndex-1)/2;i>=0;i--){
//k保存正在判断的节点
int k=i;
//如果当前k节点的子节点存在
while(k*2+1<=lastIndex){
//k节点的左子节点的索引
int biggerIndex=2*k+1;
//如果biggerIndex小于lastIndex,即biggerIndex+1代表的k节点的右子节点存在
if(biggerIndex<lastIndex){
//若果右子节点的值较大
if(data[biggerIndex]<data[biggerIndex+1]){
//biggerIndex总是记录较大子节点的索引
biggerIndex++;
}
}
//如果k节点的值小于其较大的子节点的值
if(data[k]<data[biggerIndex]){
//交换他们
swap(data,k,biggerIndex);
//将biggerIndex赋予k,开始while循环的下一次循环,重新保证k节点的值大于其左右子节点的值
k=biggerIndex;
}else{
break;
}
}
}
}

5.冒泡排序

一般不用。

将序列中所有元素两两比较,将最大的放在最后面。

将剩余序列中所有元素两两比较,将最大的放在最后面。

重复第二步,直到只剩下一个数。

如何写成代码:

设置循环次数。

设置开始比较的位数,和结束的位数。

两两比较,将最小的放到前面去。

重复2、3步,直到循环次数完毕。

代码实现如下:

6.快速排序

要求时间最快时。

选择第一个数为p,小于p的数放在左边,大于p的数放在右边。

递归的将p左边和右边的数都按照第一步进行,直到不能递归。

代码实现如下:

7.归并排序

速度仅次于快排,内存少的时候使用,可以进行并行计算的时候使用。

选择相邻两个数组成一个有序序列。

选择相邻的两个有序序列组成一个有序序列。

重复第二步,直到全部组成一个有序序列。

代码实现如下:

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
public static void mergeSort(int[] numbers, int left, int right) {  
int t = 1;// 每组元素个数
int size = right - left + 1;
while (t < size) {
int s = t;// 本次循环每组元素个数
t = 2 * s;
int i = left;
while (i + (t - 1) < size) {
merge(numbers, i, i + (s - 1), i + (t - 1));
i += t;
}
if (i + (s - 1) < right)
merge(numbers, i, i + (s - 1), right);
}
}
private static void merge(int[] data, int p, int q, int r) {
int[] B = new int[data.length];
int s = p;
int t = q + 1;
int k = p;
while (s <= q && t <= r) {
if (data[s] <= data[t]) {
B[k] = data[s];
s++;
} else {
B[k] = data[t];
t++;
}
k++;
}
if (s == q + 1)
B[k++] = data[t++];
else
B[k++] = data[s++];
for (int i = p; i <= r; i++)
data[i] = B[i];
}

8.基数排序

用于大量数,很长的数进行排序时。

将所有的数的个位数取出,按照个位数进行排序,构成一个序列。

将新构成的所有的数的十位数取出,按照十位数进行排序,构成一个序列。

代码实现如下:

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
public void sort(int[] array) {
//首先确定排序的趟数;
int max = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
int time = 0;
//判断位数;
while (max > 0) {
max /= 10;
time++;
}
//建立10个队列;
List<ArrayList> queue = new ArrayList<ArrayList>();
for (int i = 0; i < 10; i++) {
ArrayList<Integer> queue1 = new ArrayList<Integer>();
queue.add(queue1);
}
//进行time次分配和收集;
for (int i = 0; i < time; i++) {
//分配数组元素;
for (int j = 0; j < array.length; j++) {
//得到数字的第time+1位数;
int x = array[j] % (int) Math.pow(10, i + 1) / (int) Math.pow(10, i);
ArrayList<Integer> queue2 = queue.get(x);
queue2.add(array[j]);
queue.set(x, queue2);
}
int count = 0;//元素计数器;
//收集队列元素;
for (int k = 0; k < 10; k++) {
while (queue.get(k).size() > 0) {
ArrayList<Integer> queue3 = queue.get(k);
array[count] = queue3.get(0);
queue3.remove(0);
count++;
}
}
}

leetcode算法2

76 最小覆盖子串

https://leetcode.cn/problems/minimum-window-substring/

1
2
输入:s = "ADOBECODEBANC", t = "ABC"
输出:"BANC"

双指针,r每次移动一个位

如果check满足要求,移动l,循环check,直到不满足要求。

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
44
45
46
47
48
49
50
51
52
53
54
55
public class LC76 {
public String minWindow(String s, String t) {
int[] b = new int[54];
for (char c : t.toCharArray()){
b[toIndex(c)]++;
}
int[] win = new int[54];
int l=0,r=0,minLen=Integer.MAX_VALUE;
String res="";
while (r<s.length()){
int index =toIndex(s.charAt(r));
if (b[index]>0){
win[index]++;
}
while (check(win,b)){
System.out.println(l+","+r+"|"+s.substring(l,r+1));
if (r-l<minLen){
res=s.substring(l,r+1);
minLen=r-l;
}
int i=toIndex(s.charAt(l));
if (b[i]>0){
win[i]--;
}
l++;
}
r++;
}

return res;

}

private boolean check(int[] win, int[] b) {

for (int i=0;i<win.length;i++){
if (b[i]>win[i]){
return false;
}
}
System.out.println(Arrays.toString(b));
System.out.println(Arrays.toString(win));
return true;
}

private int toIndex(char c) {
int index=0;
if (c>='a' && c<='z'){
index=c-'a';
}else {
index=c-'A'+26;
}
return index;
}
}

239滑动窗口最大值

https://leetcode.cn/problems/sliding-window-maximum

1
2
3
4
5
6
7
8
滑动窗口的位置                最大值
--------------- -----
[1 3 -1] -3 5 3 6 7 3
1 [3 -1 -3] 5 3 6 7 3
1 3 [-1 -3 5] 3 6 7 5
1 3 -1 [-3 5 3] 6 7 5
1 3 -1 -3 [5 3 6] 7 6
1 3 -1 -3 5 [3 6 7] 7

双向队列维持:数值从大到小,序列号从小到大。

如果右边数值小的比新值小,移除数值小的。

如果左边最小序列号小于范围k,移除左边最小序列号

满足要求长度k,输出。

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
public int[] maxSlidingWindow(int[] nums, int k) {
if (nums.length<2){
return nums;
}
if (k>=nums.length){
return new int[]{Arrays.stream(nums).max().getAsInt()};
}


int len=nums.length,j=0;
int[] a = new int[len-k+1];
ArrayDeque<Integer> deque = new ArrayDeque<>();//值从大到小,序列号从小到大
for (int i=0;i<len;i++){
while (deque.size()>0 && nums[deque.getLast()]<=nums[i]){
deque.removeLast();
}
deque.offerLast(i);
if (deque.getFirst()<=i-k){
deque.removeFirst();
}

if (i-k+1>=0){
a[j++]=nums[deque.getFirst()];
}


}
return a;
}

124二叉树中的最大路径和

https://leetcode.cn/problems/binary-tree-maximum-path-sum

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class LC124 {
private int res=Integer.MIN_VALUE;
public int maxPathSum(TreeNode root) {
cal(root);
return res;
}

private int cal(TreeNode root) {
if (root==null){
return 0;
}
int left=cal(root.left);
int right = cal(root.right);
int sum=Math.max(Math.max(left,right)+root.val,root.val);//比较本身,和左右两边
res=Math.max(Math.max(res,sum), root.val+left+right);//比较(左+右+本身)
return sum;

}

}

647回文子串

j0 1 2 3 4
i0 1 0 0 0 1
1 1 0 1 0
2 1 0 0
3 1 0
4 1

abcba

01234

2个问题:

1为什么不用左下角?左下角是i>j,不方便理解,相当于(j->i)

2.为什么i不从上到下?比如要判断abcba(i,j)是回文,bcb(i+1,j-1)必然是回文,而(i+1,j-1)在下方。

  • abcba
  • 如果字符相等,相邻1个元素以内,必然是回文
  • 如果字符相等,比如第一个a和最后一个a,就判断bcb是否为回文。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class LC647 {
public int countSubstrings(String s) {
int len=s.length();
boolean[][] dp = new boolean[len][len];
int count=0;
for (int i=len-1;i>=0;i--){
for (int j=i;j<len;j++){
if (j-i<2 && s.charAt(i)==s.charAt(j)){
dp[i][j]=true;
count++;
}else if (s.charAt(i)==s.charAt(j) && dp[i+1][j-1]){
dp[i][j]=true;
count++;

}
}
}

return count;

}
}

96不同的二叉搜索树

https://leetcode.cn/problems/unique-binary-search-trees

n个节点
G(n)=f(1)+f(2)+…+f(n)[f(i)代表i为根节点的个数]
f(i)=G(i-1)*G(n-i)
G(i)=G(j-1)*G(i-j)…….+

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public  int numTrees(int n) {
int[] dp = new int[Math.max(n+1,5)];
dp[0]=1;
dp[1]=1;
dp[2]=2;
dp[3]=5;
if (dp[n]>0){
return dp[n];
}
for (int i=4;i<=n;i++){
int count=0;
for (int j=1;j<=i;j++){
count+=dp[j-1]*dp[i-j];
}
dp[i]=count;
}
return dp[n];
}

非leetcode算法

二维数组中-3位置找-2位置

dfs 8维以上时间太长。

bfs

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

public class ParentChildGame {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N =Integer.valueOf(sc.nextLine());
int[][] a = new int[N][N];
for (int i=0;i<N;i++){
a[i]= Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
}
int[] mom = new int[2],baby = new int[2];
for (int i=0;i<N;i++){
for (int j=0;j<N;j++){
if (a[i][j]==-3){
mom[0]=i;
mom[1]=j;
}else if (a[i][j]==-2){
baby[0]=i;
baby[1]=j;
}
}
}

bfs(a,mom[0],mom[1],baby[0],baby[1]);

System.out.println(maxRes);

}

private static int minSize = Integer.MAX_VALUE;//最小时间
private static int maxRes = -1;//最大糖果数

private static void bfs(int[][] a, int x, int y, int bi, int bj) {
boolean[][] visited = new boolean[a.length][a[0].length];
// x y 时间 糖果
PriorityQueue<int[]> priorityQueue = new PriorityQueue<>((c, d) -> {
if (c[2]!=d[2]){
return c[2]-d[2];
}
return d[3]-c[3];
});
priorityQueue.add(new int[]{x,y,0,0});
visited[x][y]=true;
while (priorityQueue.size()>0){
int[] poll =priorityQueue.poll();

int i=poll[0],j=poll[1],size=poll[2],res=poll[3];

if (i==bi && j==bj){
if (size<minSize){
minSize=size;
maxRes=res;
continue;
}
if (size==minSize && res>maxRes){
maxRes=res;
}
continue;
}

int[][] dir ={{1,0},{-1,0},{0,1},{0,-1}};
for (int[] d :dir){
int ci=i+d[0],cj=j+d[1];
if (ci>=0 && cj>=0 && ci<a.length && cj<a[0].length && visited[ci][cj]==false && a[ci][cj]!=-1){
visited[ci][cj]=true;
priorityQueue.add(new int[]{ci,cj,size+1,res+(a[ci][cj]>0?a[ci][cj]:0)});
}
}
}

}
}


重复字母的全排列

dfs用下标+set去重

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

import java.util.*;
import java.util.stream.Collectors;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int len= sc.nextInt();
String[] a= new String[len];
for (int i=0;i<len;i++){
a[i]=sc.next();
}

Set<String> result = new HashSet<>();
Arrays.sort(a);
bt(a,result,0);
result.stream().sorted().forEach(System.out::println);
}

private static void bt(String[] a, Set<String> result,int start) {
if (start==a.length){
result.add(Arrays.stream(a).collect(Collectors.joining()));
return;
}

for (int i=start;i<a.length;i++){
if (i!=start && a[i]==a[start]){
continue;
}
swap(a,i,start);
bt(a,result,start+1);
swap(a,i,start);
}

}

private static void swap(String[] a, int i, int j) {
String t =a[i];
a[i]=a[j];
a[j]=t;
}

}

dfs用list记录下标+set去重

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
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int len= sc.nextInt();
String[] a= new String[len];
for (int i=0;i<len;i++){
a[i]=sc.next();
}

HashSet<String> result = new HashSet<>();
bt(a,result,new LinkedList<Integer>());
result.stream().sorted().forEach(System.out::println);
}

private static void bt(String[] a, HashSet<String> result, LinkedList<Integer> list) {
if (list.size()==a.length){
StringBuilder sb = new StringBuilder();
for (int i=0;i<list.size();i++){
sb.append(a[list.get(i)]);
}
result.add(sb.toString());
return;
}

for (int i=0;i<a.length;i++){
if (list.contains(i)) continue;
list.addLast(i);
bt(a,result,list);
list.removeLast();
}

}


}

打印螺旋矩阵

1
2
3
4
1 2 3
* * 4
9 * 5
8 7 6
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
44
45
46
47
48
49
50
51
52
53
public class SpiralMatrixGenerator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n =sc.nextInt(),m= sc.nextInt();
int col = (n+m-1)/m;
String[][] a = new String[m][col];
int count=m*col;
int k=1;
int i=0,j=0;
while (k<=n){
while (k<=n&&j<col && a[i][j]==null){
a[i][j]= String.valueOf(k);
k++;
j++;
}
j--;
i++;

while (k<=n&&i<m&& a[i][j]==null){
a[i][j]= String.valueOf(k);
i++;
k++;
}
i--;
j--;
while (k<=n&&j>=0&& a[i][j]==null){
a[i][j]= String.valueOf(k);
j--;
k++;
}
j++;
i--;
while (k<=n&&i>0&& a[i][j]==null){
a[i][j]= String.valueOf(k);
i--;
k++;
}
i++;
j++;

}
for ( i = 0; i < a.length; i++) {
for ( j = 0; j < a[i].length; j++) {
if (a[i][j]==null){
a[i][j]="*";
}
}
System.out.println(Arrays.stream(a[i]).collect(Collectors.joining(" ")));
}
}

}

数组排列

1 ~ 9 中任意 4 个不重复的数字

2和5可以互相当作,69类似

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
public class NumberSort {

public static void main(String[] args) {
int[] a = Arrays.stream(new Scanner(System.in).nextLine().split(","))
.map(m->Integer.valueOf(m)).mapToInt(Integer::intValue).toArray();
Arrays.sort(a);
if(check(a)==false){
System.out.println(-1);
return;
}

int N = a[a.length-1];
for (int i=0;i<a.length;i++){
if (a[i]==5){
a[i]=2;
}else if (a[i]==9){
a[i]=6;
}
}
backtrack(a,0,new LinkedList<>());
System.out.println(Arrays.toString(a));
List<List<Integer>> otherList = new ArrayList<>();
for (List<Integer> list : resList){
if (list.contains(2)){
List<Integer> oList = new ArrayList<>(list);
oList.remove(Integer.valueOf(2));
oList.add(5);
otherList.add(oList);
}else if (list.contains(6)){
List<Integer> oList = new ArrayList<>(list);
oList.remove(Integer.valueOf(6));
oList.add(9);
otherList.add(oList);
}
}
resList.addAll(otherList);
for (List<Integer> list : resList){
backtrack2(list.stream().mapToInt(Integer::intValue).toArray(),new LinkedList<Integer>());
}
set=set.stream().sorted(Comparator.comparingInt(Integer::valueOf)).collect(Collectors.toList());
System.out.println(set.get(N-1));

}

private static boolean check(int[] a) {
if (a.length!=4){
return false;
}
int a2=0,a6=0;
for(int aa : a){
if (aa==2 || aa==5){
a2++;
}
if (aa==6 || aa==9){
a6++;
}
if (aa<1 || aa>9){
return false;
}
}
if (a2>1 || a6>1){
return false;
}
for (int i=1;i<a.length;i++){
if (a[i]==a[i-1]){
return false;
}
}
return true;
}

private static void backtrack2(int[] a, LinkedList<Integer> list) {
if (list.size()==a.length){
set.add(list.stream().map(Objects::toString).collect(Collectors.joining()));
}
for (int i=0;i<a.length;i++){
if (list.contains(a[i])){
continue;
}
list.addLast(a[i]);
backtrack2(a,list);
list.removeLast();
}
}

private static List<String> set = new ArrayList<>();
private static List<List<Integer>> resList = new ArrayList<>();
private static void backtrack(int[] a, int start, LinkedList<Integer> list) {
for (int i=start;i<a.length;i++){

list.addLast(a[i]);
backtrack(a,i+1,list);
list.removeLast();
}
if (list.isEmpty()==false){
resList.add((new ArrayList<>(list)));
}
}

}

二维数组中的广播

1
2
3
4
1 1 0
1 1 0
0 0 1
2
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
public class BroadcastSender  {
public static void main(String[] args) {
String[] s = new Scanner(System.in).nextLine().split(",");
int n = s.length,m=s[0].length();
int[][] a = new int[n][m];
boolean[] visited = new boolean[n];
for (int i=0;i<n;i++){
a[i] = Arrays.stream(s[i].split("")).mapToInt(Integer::parseInt).toArray();
}
int res =0;
for(int i=0;i<a.length;i++){
if (visited[i]==false){
res++;
dfs(a,i,visited);
}

}
System.out.println(res);
}

private static void dfs(int[][] a, int start,boolean[] visited) {
visited[start]=true;
for (int j=0;j<a[0].length;j++){
if (a[start][j]==1 && visited[j]==false){
dfs(a,j,visited);
}
}
}
}

伐木头收益

木头n可拆分(n-x)*x收益

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
public class Woodcutter {
public static void main(String[] args) {
int x = new Scanner(System.in).nextInt();
int[] dp = new int[x+1];//可分割第i长度时候最大收益
dp[0] =1;
for (int i=1;i<=x;i++){
dp[i]=i;
for (int j=1;j<i;j++){
dp[i] = Math.max(dp[i],dp[i-j]*j);
}
}
System.out.println(Arrays.toString(dp));
List<Integer> list = new ArrayList<>();
while (x>0){
for (int i=1;i<=x;i++){
if (dp[x]==dp[x-i]*i){
list.add(i);
x-=i;
break;
}
}
}
int[] a= list.stream().sorted().mapToInt(Integer::intValue).toArray();
for (int i=1;i<list.size();i++){
if (a[i]+a[i-1] == a[i]*a[i-1]){
a[i]=a[i]+a[i-1];
a[i-1] = 0 ;
}
}
System.out.println(Arrays.stream(a).filter(f->f!=0).sorted().boxed().map(Objects::toString).collect(Collectors.joining(" ")));
}
}

生成哈夫曼树

权重从小到大,高度从小到大

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
44
45
46
47
48
49
50
51
public class BuildHuffmanNode {

static class HuffmanNode{
public int weight,height;
public HuffmanNode left,right;

public HuffmanNode(int weight, int height) {
this.weight = weight;
this.height = height;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
PriorityQueue<HuffmanNode> queue = new PriorityQueue<>((Comparator<HuffmanNode>) (a, b) -> {
if (a.weight!=b.weight){
return a.weight-b.weight;
}
return a.height-b.height;
});
for (int i=0;i<n;i++){
int a= sc.nextInt();
queue.offer(new HuffmanNode(a,0));
}
HuffmanNode root = buildHuffmanTree(queue);
System.out.println(inOrder(new StringBuilder(),root));
}

private static String inOrder(StringBuilder sb,HuffmanNode root) {
if (root==null){
return null;
}
inOrder(sb,root.left);
sb.append(root.weight+" ");
inOrder(sb,root.right);
return sb.toString().trim();
}

private static HuffmanNode buildHuffmanTree(PriorityQueue<HuffmanNode> queue) {
while (queue.size()>1){
HuffmanNode a = queue.poll();
HuffmanNode right = queue.poll();
HuffmanNode parent = new HuffmanNode(a.weight + right.weight,Math.max(a.height,right.height)+1);
parent.left=a;
parent.right=right;
queue.offer(parent);
}
return queue.poll();
}

}

多任务启动顺序

如果同时有多个任务要执行,则根据任务名称字母顺序排序

A->B C->B

BAC

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

public class MultiTaskScheduler {
public static void main(String[] args) {
//C->D C->B A->B
String[] s = new Scanner(System.in).nextLine().split(" ");
Map<String, List<String>> map = new HashMap<>();
for (String a : s){
String[] b= a.split("->");
if (map.containsKey(b[1])){
List<String> list =map.get(b[1]);
list.add(b[0]);
map.put(b[1],list);
}else {
List<String> list = new ArrayList<>();
list.add(b[0]);
map.put(b[1],list);
}
}

List<String> l = new ArrayList<>();
for (String key : map.keySet()){
// System.out.println(key+"=>"+map.get(key));
boolean isInclude= false;
for (List<String> list : map.values()){
if (list.contains(key)){
isInclude=true;
break;
}
}
if (isInclude==false){
l.add(key);
}
}
PriorityQueue<String> queue = new PriorityQueue<>(Comparator.naturalOrder());
// System.out.println("l:"+l);
for (int i=0;i<l.size();i++){
queue.offer(l.get(i));
}

List<String> res = new ArrayList<>();
List<String> inList = new ArrayList<>();//包含

while (queue.isEmpty()==false || inList.isEmpty()==false){
if (queue.isEmpty()) {
// 这里改变为检查inList中的任务是否可以移入queue
List<String> readyToQueue = new ArrayList<>();
for (String task : inList) {
boolean isInclude = true;
for (List<String> list : map.values()) {
if (list.contains(task)) {
isInclude = false;
break;
}
}
if (isInclude) {
readyToQueue.add(task);
}
}
inList.removeAll(readyToQueue);
queue.addAll(readyToQueue);

if (queue.isEmpty() && inList.isEmpty()) {
break; // 防止死循环
}
}

String key = queue.poll();
boolean isInclude =false;
for (List<String> list : map.values()){
if (list.contains(key)){
isInclude=true;
break;
}
}
if (isInclude){
inList.add(key);
continue;
}

if (res.contains(key)==false){
res.add(key);
}

List<String> list =map.get(key);
map.remove(key);

if (list==null){
continue;
}

for (int i=0;i<list.size();i++){
inList.add(list.get(i));
}
}
System.out.println(res.stream().collect(Collectors.joining(" ")));
}
}

长度为m的和为n的数组个数

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
public class MooncakeAllocator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt();
int n = scanner.nextInt();
scanner.close();
for (int i=1;i<=n/m;i++){ //数组的第一个元素只能是i
processCake(m,n,1,i,i);
}

System.out.println(c);
}
private static int c=0;
private static void processCake(int len, int n, int start,int sum,int pre ) {
if (start==len) {
if (sum==n){
c++;
}
return;
}
//数组后面的元素比前一个元素大0-3
for (int i = pre; i<=pre+3 && i<=n-len+1; i++) {
if (i+sum<=n){
processCake(len, n,start+1,i+sum,i);
}
}
}
}

抢7游戏

A报N,B报N-1或N-2,依次循环,保证B为7的组合。

递归:数据大会超时

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Main {
public static void main(String[] args) {
int n = new Scanner(System.in).nextInt();
System.out.println(sevenGame(n, false));
}
private static int sevenGame(int n, boolean isB) {
if (n<7){
return 0;
}
if (n == 7) {
return isB ? 1 : 0;
}
int res = 0;
if (n > 1) {
res += sevenGame(n - 1, !isB);
}
if (n > 2) {
res += sevenGame(n - 2, !isB);
}
return res;
}
}

动态规划

n属于A开始,A=B的上一个(可能是i+1,i+2)

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
private static BigInteger sevenGameDp(int n) {
if (n <= 7) {
return BigInteger.ZERO;
}
BigInteger[][] dp = new BigInteger[n + 1][2];
for (int i=0;i<dp.length;i++){
for (int j=0;j<dp[0].length;j++){
dp[i][j]=BigInteger.ZERO;
}
}
dp[n][0] = BigInteger.ONE; // A开始
dp[n][1] = BigInteger.ZERO;

for (int i = n ; i >= 7; i--) {
if (i+1<=n){
dp[i][0] = dp[i][0].add(dp[i + 1][1]);
dp[i][1] = dp[i][1].add(dp[i + 1][0]);
}
if (i+2<=n){
dp[i][0] = dp[i][0].add(dp[i + 2][1]);
dp[i][1] = dp[i][1].add(dp[i + 2][0]);
}
}
return dp[7][1];
}

游乐园最低消费

输入一行,分别为一日票(1天)、三日票(3天)、周票(7天)和月票(30天)

输入第二行,小王计划游玩日期数组为days,1 ≤ days.length ≤ 365,1 ≤ days[i] ≤ 365,默认顺序为升序。
输出描述:完成游玩计划的最低消费。

会有部分Memory Exceeded的做法

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
private static void dfs(int[] costs, List<Integer> dayList, int start,int maxIndex, LinkedList<Integer> list) {
while (start<=maxIndex && dayList.contains(start)==false){
start++;
}


if (list.stream().mapToInt(Integer::intValue).sum()>=minCost){
return;
}

List<Integer> indexCost = List.of(1,3,7,30);
if (start>maxIndex ){
minCost= Math.min(minCost,list.stream().mapToInt(Integer::intValue).sum());
return;
}


for (int i=0;i<4;i++){
list.addLast(costs[i]);
start+=indexCost.get(i);
dfs(costs,dayList,start,maxIndex,list);
list.removeLast();
start-=indexCost.get(i);

}
}

LinkedList list演变为currentCost,又成功了多几个,数量大还是回溯深度过大

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
private static void dfs(int[] costs, List<Integer> dayList, int start,int maxIndex, int currentCost) {
while (start<=maxIndex && dayList.contains(start)==false){
start++;
}


if (currentCost>=minCost){
return;
}

List<Integer> indexCost = List.of(1,3,7,30);
if (start>maxIndex ){
minCost= Math.min(minCost,currentCost);
return;
}


for (int i=0;i<4;i++){
currentCost+=costs[i];
start+=indexCost.get(i);
dfs(costs,dayList,start,maxIndex,currentCost);
currentCost-=costs[i];
start-=indexCost.get(i);

}
}

dp动态规划

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private static int minDp(int[] costs, List<Integer> dayList) {
int[] dp = new int[dayList.get(dayList.size() - 1) + 1];
for (int i = 1; i < dp.length; i++) {
if (dayList.contains(i) == false) {
dp[i] = dp[i - 1];//在非游玩天数,dp[i]应继承前一天的值,因为当天不需要额外的花费
continue;
}

// 第一个不能Math.min(dp[i], (i -1>0?dp[i - 1]:0) + costs[0]);
dp[i] = (i - 1 > 0 ? dp[i - 1] : 0) + costs[0];// dp[i - 1] + costs[0];
dp[i] = Math.min(dp[i], (i -3>0?dp[i - 3]:0) + costs[1]);
dp[i] = Math.min(dp[i], (i -7>0?dp[i - 7]:0) + costs[2]);
dp[i] = Math.min(dp[i], (i -30>0?dp[i - 30]:0)+ costs[3]);

}
return dp[dp.length - 1];
}

分披萨

AB从缺口两边分披萨

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
44
45
46
47
48
49
50
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i]=sc.nextInt();
}

long max = 0;
memo= new long[n][n];
for (int i = 0; i < n; i++) {
for (long[] m :memo){
Arrays.fill(m,0);
}

int temp=array[0];
for (int j=1;j<n;j++){
array[j-1]=array[j];
}
array[n-1]=temp;

max = Math.max(process(array,true,0,array.length-1), max);
}
System.out.println(max);
}
private static long [][] memo;//记忆搜索
private static long process(int[] array, boolean isTrueA,int left,int right) {
if (left>right){
return 0;
}
if (isTrueA==false){
if (array[left]>array[right]){
return process(array,true,left+1,right);
}else {
return process(array,true,left,right-1);
}
}else {
if (memo[left][right]!=0){
return memo[left][right];
}
long a = array[left]+process(array,false,left+1,right);
long b =array[right]+process(array,false,left,right-1);
long max= Math.max(a,b);
memo[left][right]=max;
return max;
}
}

}

数组连续和

长度3数组连续大于等于7的个数

3 7
3 4 7

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
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
int[] a = new int[n];
for (int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int v = sc.nextInt();
int l=0,r=0,winSum=a[0];
int max =0;
while (r<n){
if (winSum<=v){
max=Math.max(r-l+1,max);
}else {
winSum-=a[l];
l++;
}

r++;
if (r>=n){
break;
}
winSum+=a[r];
}
System.out.println(max);
}
}

左上角到右下角(各值最大的)路径中的最小值

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n =Integer.valueOf(sc.nextLine()),m=Integer.valueOf(sc.nextLine());
int[][] a = new int[n][m];
int left=0,right=0,res=0;
for (int i=0;i<n;i++){
a[i]= Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::valueOf).toArray();
for (int aa:a[i]){
right=right>aa?right:aa;
}
}

while (left<=right){
int mid =(left+right)/2;//默认是最小的
if (bfs(a,n,m,mid)){//dfs(a,0,0,n,m,mid,new boolean[n][m])
res=mid;
left=mid+1;
}else {
right=mid-1; //找不到就变小
}
}
System.out.println(res);
}

private static boolean bfs(int[][] a, int n, int m, int k) {
if (a[0][0]<k || a[n-1][m-1]<k){
return false;
}
boolean[][] visited= new boolean[n][m];
LinkedList<int[]> list = new LinkedList<>();
visited[0][0] =true;
list.add(new int[]{0,0});
int[][] dir = {{0,1},{0,-1},{1,0},{-1,0}};
while (list.isEmpty()==false){
int[] poll = list.removeFirst();
int x=poll[0],y=poll[1];
if (x==n-1 && y==m-1){
return true;
}

for (int[] d:dir){
int i=d[0]+x,j=d[1]+y;
if (i>=0 && j>=0 && i<n && j<m && visited[i][j]==false && a[i][j]>=k){
visited[i][j]=true;
list.offer(new int[]{i,j});
}
}

}
return false;
}


//数据大会超时
private static boolean dfs(int[][] a, int i, int j, int n, int m, int k, boolean[][] visited) {
if (i<0 || i>=n || j<0 || j>=m || visited[i][j] || a[i][j]<k){
return false;
}
if (i==n-1 && j==m-1){
return true;
}
visited[i][j]=true;
boolean b= dfs(a,i+1,j,n,m,k,visited)
||dfs(a,i-1,j,n,m,k,visited)
||dfs(a,i,j+1,n,m,k,visited)
||dfs(a,i,j-1,n,m,k,visited);
visited[i][j]=false;
return b;
}
}

24点扑克牌

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.*;

public class Main {
public static void main(String[] args) {
int[] a = Arrays.stream(new Scanner(System.in).nextLine()
.split(" ")).mapToInt(Integer::parseInt).toArray();
System.out.println(getResult(a));

}
private static List<List<Integer>> resList;
private static boolean getResult(int[] a) {
resList = new ArrayList<>();
dfs(a,new LinkedList<>(),new LinkedList<>());
for (List<Integer> list : resList){
if (check(list)){
return true;
}
}
return false;

}

private static boolean check(List<Integer> list) {
for (double a:cal(list.get(0),list.get(1))){
for (double b:cal(list.get(2),a)){
for (double res:cal(list.get(3),b)){
if (24==res){
return true;
}
}
}
}
return false;

}


private static List<Double> cal(double a, double b) {
List<Double> list=new ArrayList<>();
list.add((double) (a+b));
list.add((double) (a-b));
list.add((double) (b-a));
list.add((double) (a/b));
list.add((double) (b/a));
list.add((double) (a*b));
return list;

}

private static void dfs(int[] a, LinkedList<Integer> indexList, LinkedList<Integer> list) {
if (list.size()==4){
resList.add(new ArrayList<>(list));
return;
}

for (int i=0;i<4;i++){
if (indexList.contains(i)){
continue;
}
indexList.addLast(i);
list.addLast(a[i]);
dfs(a,indexList,list);
indexList.removeLast();
list.removeLast();
}
}

}

android:delete avb

avb :https://source.android.google.cn/docs/core/architecture/kernel/mounting-partitions-early

file: vendor/etc/fstab.qcom

clears all AVB code (except for the 7 AVBs in the figure)

Find the line of code [userdata] with code similar to this, and delete it.

【fileencryption=ice,wrappedkey,keydirectory=/metadata/vold/metadata_encryption,】

MIUI delete screen lock

1
/data/system/locksettings

Similar to this kind of file, del two. The screen lock key was deleted.

crDroid delete screen lock

1
/data/system/locksettings.db

Already flashed Gapps’ crDroid, after re-flashing the rom. Then restore the backup and the screen passcode will change. At this time, you need to delete the locksettings.db file. If crDroid is stuck on the second screen after restarting, it may be caused by Gapps and needs to be re-flashed.

Check the current A/B slots for Android.

In the Android system, if the device supports A/B partitioning, the system will create two partitions in the device, one is the currently used partition and the other is the alternate partition. These two partitions are called slots. When using the adb shell command, you can see which slot the current system belongs to with the following command:

1
getprop ro.boot.slot_suffix

This command returns the slot number to which the current system belongs, for example, if the returned result is “_a”, it means that the current system belongs to slot A.

If the returned result is “_b”, it means that the current system belongs to slot B.

git-Modify the userName after push

This method is suitable for updating the username after pushing.

cd the root of THE GIT PROJECT

Replace the following parameters.

OLD_EMAIL
CORRECT_NAME
CORRECT_EMAIL

executive:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
git filter-branch  -f --env-filter '
OLD_EMAIL="oldEmail@foxmail.com"
CORRECT_NAME="newName"
CORRECT_EMAIL="new@email.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

Push up the dev branch.

1
git push --force --tags origin 'refs/heads/dev'

centos7 update ssh port

0x01 open ports firewall

It should include 22 port

1
2
3
4
systemctl status firewalld
firewall-cmd --zone=public --list-all
firewall-cmd --permanent --zone=public --add-port=222/tcp
firewall-cmd --permanent --zone=public --add-port=22/tcp

0x02 update sshd config

1
sudo vi /etc/ssh/sshd_config

add:

1
2
Port 22
Port 222

0x03 install semanage

It involve with the problem of SELinux when we update ssh ports.

1
2
3
yum provides semanage
yum -y install policycoreutils-python
semanage port -a -t ssh_port_t -p tcp 222

and

1
2
3
systemctl restart sshd
or
reboot

0x04 end

1
2
firewall-cmd --permanent --zone=public --remove-port=22/tcp
firewall-cmd --reload

vi /etc/ssh/sshd_config & remove Port 22

Android自带应用精简

个别软件,前提要去卡米

1
2
3
4
5
6
7
8
9
10
public class RmRfTest {
public static void main(String[] args) {

for (String str : FileUtil.readUtf8Lines("rm44.txt")) {
System.out.println(str + "||||||" + RuntimeUtil.execForStr(str));
ThreadUtil.sleep(200);
}
}
}

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
adb shell pm uninstall --user 0  com.miui.systemAdSolution
adb shell pm uninstall --user 0 com.miui.analytics
adb shell pm uninstall --user 0 com.xiaomi.gamecenter.sdk.service
adb shell pm uninstall --user 0 com.xiaomi.gamecenter
adb shell pm uninstall --user 0 com.sohu.inputmethod.sogou.xiaomi
adb shell pm uninstall --user 0 com.miui.player
adb shell pm uninstall --user 0 com.miui.video
adb shell pm uninstall --user 0 com.miui.notes
adb shell pm uninstall --user 0 com.miui.translation.youdao
adb shell pm uninstall --user 0 com.miui.translation.kingsoft
adb shell pm uninstall --user 0 com.android.email
adb shell pm uninstall --user 0 com.xiaomi.scanner
adb shell pm uninstall --user 0 com.miui.hybrid
adb shell pm uninstall --user 0 com.miui.bugreport
adb shell pm uninstall --user 0 com.milink.service
adb shell pm uninstall --user 0 com.android.browser
adb shell pm uninstall --user 0 com.miui.yellowpage
adb shell pm uninstall --user 0 com.xiaomi.payment
adb shell pm uninstall --user 0 com.mipay.wallet
adb shell pm uninstall --user 0 com.android.soundrecorder
adb shell pm uninstall --user 0 com.miui.voiceassist
adb shell pm uninstall --user 0 com.miui.touchassistant
adb shell pm uninstall --user 0 com.xiaomi.mitunes
adb shell pm uninstall --user 0 com.xiaomi.pass
adb shell pm uninstall --user 0 com.android.wallpaper
adb shell pm uninstall --user 0 com.android.wallpaper.livepicker
adb shell pm uninstall --user 0 com.miui.klo.bugreport
adb shell pm uninstall --user 0 com.miui.securityinputmethod
adb shell pm uninstall --user 0 com.baidu.input_mi
adb shell pm uninstall --user 0 com.iflytek.inputmethod.miui
adb shell pm uninstall --user 0 com.sohu.inputmethod.sogou.xiaomi
adb shell pm uninstall --user 0 com.miui.personalassistant
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
adb shell pm uninstall --user 0 com.miui.accessibility
adb shell pm uninstall --user 0 com.miui.analytics
adb shell pm uninstall --user 0 com.miui.aod
adb shell pm uninstall --user 0 com.miui.bugreport
adb shell pm uninstall --user 0 com.miui.cleanmaster
adb shell pm uninstall --user 0 com.miui.compass
adb shell pm uninstall --user 0 com.miui.contentextension
adb shell pm uninstall --user 0 com.miui.easygo
adb shell pm uninstall --user 0 com.miui.huanji
adb shell pm uninstall --user 0 com.miui.hybrid
adb shell pm uninstall --user 0 com.miui.hybrid.accessory
adb shell pm uninstall --user 0 com.miui.maintenancemode
adb shell pm uninstall --user 0 com.miui.miservice
adb shell pm uninstall --user 0 com.miui.mishare.connectivity
adb shell pm uninstall --user 0 com.miui.miwallpaper.earth
adb shell pm uninstall --user 0 com.miui.miwallpaper.geometry
adb shell pm uninstall --user 0 com.miui.miwallpaper.mars
adb shell pm uninstall --user 0 com.miui.miwallpaper.saturn
adb shell pm uninstall --user 0 com.miui.miwallpaper.snowmountain
adb shell pm uninstall --user 0 com.miui.newhome
adb shell pm uninstall --user 0 com.miui.newmidrive
adb shell pm uninstall --user 0 com.miui.nextpay
adb shell pm uninstall --user 0 com.miui.notes
adb shell pm uninstall --user 0 com.miui.smarttravel
adb shell pm uninstall --user 0 com.miui.systemAdSolution
adb shell pm uninstall --user 0 com.miui.touchassistant
adb shell pm uninstall --user 0 com.miui.thirdappassistant
adb shell pm uninstall --user 0 com.miui.tsmclient
adb shell pm uninstall --user 0 com.miui.voiceassist
adb shell pm uninstall --user 0 com.miui.voicetrigger
adb shell pm uninstall --user 0 com.miui.weather2
adb shell pm uninstall --user 0 com.miui.yellowpage
adb shell pm uninstall --user 0 com.miui.translation.kingsoft
adb shell pm uninstall --user 0 com.miui.translation.youdao
adb shell pm uninstall --user 0 com.miui.translation.xmcloud
adb shell pm uninstall --user 0 com.miui.translationservice
adb shell pm uninstall --user 0 com.miui.cloudbackup
adb shell pm uninstall --user 0 com.miui.cloudservice
adb shell pm uninstall --user 0 com.miui.micloudsync
adb shell pm uninstall --user 0 com.xiaomi.ab
adb shell pm uninstall --user 0 com.xiaomi.drivemode
adb shell pm uninstall --user 0 com.xiaomi.gamecenter
adb shell pm uninstall --user 0 com.xiaomi.gamecenter.sdk.service
adb shell pm uninstall --user 0 com.xiaomi.joyose
adb shell pm uninstall --user 0 com.xiaomi.jr
adb shell pm uninstall --user 0 com.xiaomi.macro
adb shell pm uninstall --user 0 com.xiaomi.mi_connect_service
adb shell pm uninstall --user 0 com.xiaomi.mibrain.speech
adb shell pm uninstall --user 0 com.xiaomi.migameservice
adb shell pm uninstall --user 0 com.xiaomi.mirror
adb shell pm uninstall --user 0 com.xiaomi.payment
adb shell pm uninstall --user 0 com.xiaomi.shop
adb shell pm uninstall --user 0 com.xiaomi.finddevice
adb shell pm uninstall --user 0 com.xiaomi.micloud.sdk
adb shell pm uninstall --user 0 com.mfashiongallery.emag
adb shell pm uninstall --user 0 com.mi.health
adb shell pm uninstall --user 0 com.mi.liveassistant
adb shell pm uninstall --user 0 com.mipay.wallet
adb shell pm uninstall --user 0 com.achievo.vipshop
adb shell pm uninstall --user 0 com.baidu.searchbox
adb shell pm uninstall --user 0 com.bsp.catchlog
adb shell pm uninstall --user 0 com.dianping.v1
adb shell pm uninstall --user 0 com.dragon.read
adb shell pm uninstall --user 0 com.duokan.reader
adb shell pm uninstall --user 0 com.eastmoney.android.berlin
adb shell pm uninstall --user 0 com.Qunar
adb shell pm uninstall --user 0 com.qxwz.ps.hpls
adb shell pm uninstall --user 0 com.sina.weibo
adb shell pm uninstall --user 0 com.taobao.litetao
adb shell pm uninstall --user 0 com.tencent.mtt
adb shell pm uninstall --user 0 com.UCMobile
adb shell pm uninstall --user 0 ctrip.android.view
adb shell pm uninstall --user 0 tv.pps.mobile
adb shell pm uninstall --user 0 com.android.email
adb shell pm uninstall --user 0 com.android.managedprovisioning
adb shell pm uninstall --user 0 com.android.printspooler
adb shell pm uninstall --user 0 com.android.quicksearchbox
adb shell pm uninstall --user 0 com.android.internal.systemui.navbar.threebutton
1
2
3
4
5
6
7
8
9
10
adb shell pm disable-user com.miui.daemon
adb shell pm disable-user com.xiaomi.xmsf
adb shell pm disable-user com.xiaomi.simactivate.service
adb shell pm disable-user com.xiaomi.xmsfkeeper
adb shell pm uninstall --user 0 com.miui.cloudservice
adb shell pm uninstall --user 0 com.xiaomi.account
adb shell pm uninstall --user 0 com.miui.cloudbackup
adb shell pm uninstall --user 0 com.xiaomi.market
adb shell pm uninstall --user 0 com.android.thememanager
adb shell pm uninstall --user 0 com.miui.cloudservice.sysbase
1
2
3
4
5
6
7
8
9
10
11
adb shell pm uninstall --user 0 com.miui.carlink
adb shell pm uninstall --user 0 com.unionpay.tsmservice.mi
adb shell pm uninstall --user 0 com.xiaomi.powerchecker
adb shell pm uninstall --user 0 com.miui.securityadd
adb shell pm uninstall --user 0 com.miui.core.internal.assistant
adb shell pm uninstall --user 0 com.miui.vipservice
adb shell pm uninstall --user 0 com.miui.phrase
adb shell pm uninstall --user 0 com.miui.compass
adb shell pm uninstall --user 0 com.miui.cleanmaster
adb shell pm uninstall --user 0 org.mipay.android.manager
adb shell pm uninstall --user 0 com.xiaomi.scanner

github不同项目pages使用不同的域名

github不同项目pages使用不同的域名

CNAME方式

最常见的是 CNAME方式: .github.io 或 .github.io

具体参考 https://docs.github.com/cn/pages/configuring-a-custom-domain-for-your-github-pages-site/about-custom-domains-and-github-pages

比如添加 www.example.com 指向 example.github.io在项目根目录 添加文件CNAME,

里面内容: www.example.com

之后的项目files的pages默认地址是www.example.com/files

默认方式

如果同一个GitHub账号上另一个项目比如files也开启一个pages

那么默认的访问路径是www.example.com/files

A方式

如果想把www.example.com/files 改成 file.example.com,可以通过A方式.

CNAME 文件对应一个域名, 比如file.example.com,

在域名里面A方式配置

img

效果

  • Copyrights © 2020-2025 Lin