File tree

4 files changed

+138
-1
lines changed

4 files changed

+138
-1
lines changed
Some generated files are not rendered by default. Learn more about customizing how changed files appear on .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.util.Arrays;
2+
3+
/**
4+
* @Author: iqqcode
5+
* @Date: 2020-10-19 09:55
6+
* @Description:
7+
*/
8+
public class Main {
9+
public static void main(String[] args) {
10+
int[][] arr = {{1, 3, 2}, {9, 20, 5}, {8, 9}};
11+
Arrays.stream(arr);
12+
int i = 0;
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package xunlei;
2+
3+
/**
4+
* @Author: iqqcode
5+
* @Date: 2020-10-19 18:52
6+
* @Description:迅雷笔试
7+
*/
8+
9+
import java.util.*;
10+
11+
public class Solution {
12+
static List<String> list = new ArrayList<>();
13+
14+
public static void main(String[] args) {
15+
Scanner in = new Scanner(System.in);
16+
int n = in.nextInt();
17+
in.nextLine();
18+
String[][] nodes = new String[4][2];
19+
Set<String> set = new HashSet<>();
20+
String a = null, b = null;
21+
for (int i = 0; i < n; i++) {
22+
a = nodes[i][0] = in.next();
23+
b = nodes[i][1] = in.next();
24+
set.add(a);
25+
set.add(b);
26+
}
27+
28+
//拿到头结点
29+
for (int i = 0; i < nodes.length; i++) {
30+
if (set.contains(nodes[i][1])) {
31+
set.remove(nodes[i][1]);
32+
}
33+
}
34+
//获取集合的第一个元素
35+
String head = set.iterator().next();
36+
list.add(head);
37+
listRefactor(nodes, head);
38+
for (int i = 0; i < list.size(); i++) {
39+
System.out.println(list.get(i));
40+
}
41+
}
42+
43+
private static void listRefactor(String[][] nodes, String head) {
44+
for (int i = 0; i < nodes.length; i++) {
45+
if (nodes[i][0].equals(head)) {
46+
list.add(nodes[i][1]);
47+
listRefactor(nodes, nodes[i][1]);
48+
}
49+
}
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package xunlei;
2+
3+
/**
4+
* @Author: iqqcode
5+
* @Date: 2020-10-19 18:52
6+
* @Description:迅雷笔试-2 杨氏矩阵元素由小到大有序输出
7+
* [case]:
8+
* 4 3 // 4行3列
9+
* 1 2 3
10+
* 2 3 4
11+
* 4 5 6
12+
* 6 7 8
13+
*/
14+
15+
import java.util.*;
16+
17+
public class Solution2 {
18+
public static void main(String[] args) {
19+
Scanner in = new Scanner(System.in);
20+
int m = in.nextInt();
21+
int n = in.nextInt();
22+
in.nextLine();
23+
int[][] arr = new int[m][n];
24+
for (int i = 0; i < m; i++) {
25+
for (int j = 0; j < n; j++) {
26+
arr[i][j] = in.nextInt();
27+
}
28+
}
29+
youngExtract(arr);
30+
}
31+
32+
public static void youngExtract(int[][] arr) {
33+
int min = 0;
34+
for (int i = arr.length - 1; i >= 0; i--) {
35+
for (int j = arr[0].length - 1; j >= 0; j--) {
36+
min = arr[0][0];
37+
if (min != Integer.MAX_VALUE) {
38+
System.out.println(min);
39+
}
40+
arr[0][0] = arr[i][j];
41+
arr[i][j] = Integer.MAX_VALUE;
42+
youngHeapify(arr, 0, 0);
43+
}
44+
}
45+
}
46+
47+
48+
public static void youngHeapify(int[][] arr, int row, int col) {
49+
int N = arr.length;
50+
int M = arr[0].length;
51+
int min_i = row;
52+
int min_j = col;
53+
if (min_j < M - 1 && arr[row][col + 1] != Integer.MAX_VALUE && arr[min_i][min_j] > arr[row][col + 1]) {
54+
min_i = row;
55+
min_j = col + 1;
56+
}
57+
58+
if (min_i < N - 1 && arr[row + 1][col] != Integer.MAX_VALUE && arr[min_i][min_j] > arr[row + 1][col]) {
59+
min_i = row + 1;
60+
min_j = col;
61+
}
62+
63+
if (min_i != row || min_j != col) {
64+
int tmp = arr[min_i][min_j];
65+
arr[min_i][min_j] = arr[row][col];
66+
arr[row][col] = tmp;
67+
youngHeapify(arr, min_i, min_j);
68+
}
69+
}
70+
}
71+
72+

0 commit comments

Comments
 (0)