File tree

15 files changed

+667
-2
lines changed

15 files changed

+667
-2
lines changed
Binary file not shown.
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
@@ -8,6 +8,18 @@
88
*/
99
public class Main {
1010
public static void main(String[] args) {
11-
System.out.println(5 & 1);
11+
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
12+
int target = 7;
13+
int left = 0, right = arr.length - 1;
14+
while(left < right) {
15+
int mid = (left + right) >>> 1;
16+
if(target > arr[mid]) {
17+
left = mid + 1;
18+
} else {
19+
right = mid;
20+
}
21+
}
22+
//return arr[left] == target ? left : -1;
23+
System.out.println(left);
1224
}
1325
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package ThoughtWorks;
2+
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) {
7+
Scanner in = new Scanner(System.in);
8+
System.out.println("请输入地图 m-行 和 n-列: ");
9+
int m = in.nextInt();
10+
int n = in.nextInt();
11+
in.nextLine();
12+
//输入的字符串数量为:(n+2)/3*m;4*6的为:(4+2)/3*4=8
13+
int numStr = (n + 2) / 3 * m;
14+
System.out.println(numStr);
15+
String[] strs = new String[numStr];
16+
char[][] chars = new char[numStr][5];
17+
char[][] map = new char[m][n];
18+
for (int i = 0; i < numStr; i++) {
19+
strs[i] = in.next();
20+
}
21+
22+
for (int i = 0; i < numStr; i++) {
23+
chars[i] = strs[i].toCharArray();
24+
}
25+
26+
int k = 0;
27+
for (int i = 0, j = 0; i < m; i++, j++) {
28+
k = 0;
29+
map[j][k++] = chars[i][4];
30+
map[j][k++] = chars[i][0];
31+
map[j][k++] = chars[i][2];
32+
}
33+
for (int i = numStr - 1, j = 0; i >= m; i--, j++) {
34+
k = 3;
35+
map[j][k++] = chars[i][4];
36+
map[j][k++] = chars[i][0];
37+
map[j][k++] = chars[i][2];
38+
}
39+
40+
for (int i = 0; i < m; i++) {
41+
for (int j = 0; j < n; j++) {
42+
System.out.print(map[i][j]);
43+
}
44+
System.out.println();
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ThoughtWorks;
2+
3+
/**
4+
* @Author: iqqcode
5+
* @Date: 2020-10-23 22:11
6+
* @Description:
7+
*/
8+
9+
import java.util.*;
10+
11+
public class Solution {
12+
13+
public static void main(String[] args) {
14+
Scanner in = new Scanner(System.in);
15+
int row = in.nextInt();
16+
int col = in.nextInt();
17+
18+
// 创建地图
19+
int[][] map = createMap(row, col);
20+
// 螺旋飞行
21+
//new SolutionOne().spiralTravel(map, 0, map[0].length - 1, 0, map.length - 1);
22+
23+
// 跳跃飞行
24+
new SolutionTwo().skipTravel(map, 0, map[0].length - 1, 1, map.length - 1);
25+
// 打印结果
26+
printMap(map);
27+
}
28+
29+
public static int[][] createMap(int row, int col) {
30+
return new int[row][col];
31+
}
32+
33+
public static void printMap(int[][] map) {
34+
for (int i = 0; i < map.length; i++) {
35+
for (int j = 0; j < map[0].length; j++) {
36+
System.out.print(map[i][j]);
37+
}
38+
System.out.println();
39+
}
40+
}
41+
}
42+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ThoughtWorks;
2+
3+
/**
4+
* @Author: iqqcode
5+
* @Date: 2020-10-23 22:18
6+
* @Description:
7+
*/
8+
public class SolutionOne {
9+
public void spiralTravel(int[][] map, int left, int right, int up, int down) {
10+
int count = 0;
11+
while (true) {
12+
// 左到右
13+
for (int col = left; col <= right; col++) {
14+
takePhoto(map, up, col, count++);
15+
}
16+
if (++up > down) break;
17+
// 上到下
18+
for (int row = up; row <= down; row++) {
19+
takePhoto(map, row, right, count++);
20+
}
21+
if (--right < left) break;
22+
// 右到左
23+
for (int col = right; col >= left; col--) {
24+
takePhoto(map, down, col, count++);
25+
}
26+
if (--down < up) break;
27+
// 下到上
28+
for (int row = down; row >= up; row--) {
29+
takePhoto(map, row, left, count++);
30+
}
31+
if (++left > right) break;
32+
}
33+
}
34+
35+
private void takePhoto(int[][] map, int row, int col, int count) {
36+
if (count % 3 == 0) {
37+
map[row][col] = 1;
38+
}
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package ThoughtWorks;
2+
3+
/**
4+
* @Author: iqqcode
5+
* @Date: 2020-10-23 22:18
6+
* @Description:
7+
*/
8+
public class SolutionTwo {
9+
10+
public void skipTravel(int[][] map, int left, int right, int up, int down) {
11+
boolean leftToRight = true;
12+
while (true) {
13+
if (leftToRight) {
14+
moveL2R(map, left, right, up);
15+
leftToRight = false;
16+
} else {
17+
moveR2L(map, left, right, up);
18+
leftToRight = true;
19+
}
20+
// 边界判断
21+
if (up + 1 == down) {
22+
break;
23+
}
24+
// 跳跃条件
25+
if (up + 3 < down) {
26+
up = leftToRight ? skip(map, up, left, 3) : skip(map, up, right, 3);
27+
} else if (up + 3 == down) {
28+
up = leftToRight ? skip(map, up, left, 2) : skip(map, up, right, 2);
29+
} else {
30+
up = leftToRight ? skip(map, up, left, 1) : skip(map, up, right, 1);
31+
}
32+
}
33+
}
34+
35+
private int skip(int[][] map, int up, int direction, int count) {
36+
for (int i = 0; i < count; i++) {
37+
map[up++][direction] = 1;
38+
}
39+
return up;
40+
}
41+
42+
43+
private void moveL2R(int[][] map, int left, int right, int up) {
44+
for (int col = left; col <= right; col++) {
45+
map[up][col] = 1;
46+
}
47+
}
48+
49+
private void moveR2L(int[][] map, int left, int right, int up) {
50+
for (int col = right; col >= left; col--) {
51+
map[up][col] = 1;
52+
}
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package didipractice;
2+
3+
/**
4+
* @Author: iqqcode
5+
* @Date: 2020-10-21 14:20
6+
* @Description:
7+
*/
8+
9+
import java.util.*;
10+
11+
public class Main {
12+
13+
14+
public static void main(String[] args) {
15+
int[] arr_five = new int[10];
16+
for (int i = 0; i < arr_five.length; i++) {
17+
arr_five[i] = randFive();
18+
}
19+
20+
System.out.println("生成1-5的随机数: " + Arrays.toString(arr_five));
21+
22+
23+
int[] arr_seven = new int[10];
24+
for (int i = 0; i < arr_seven.length; i++) {
25+
arr_seven[i] = getRandomNumSevenI();
26+
}
27+
28+
// 测试统计
29+
Map<Integer, Integer> map = new HashMap<>();
30+
System.out.println("<<测试方法二>>");
31+
for (int i = 0; i < 1000000; i++) {
32+
33+
// 测试方法二
34+
int temp = getRandomNumSevenII();
35+
36+
if(map.containsKey(temp)) {
37+
map.put(temp, map.get(temp) + 1);
38+
} else {
39+
map.put(temp, 1);
40+
}
41+
}
42+
43+
map.forEach((key, value) -> {
44+
System.out.println(key + " -- 出现次数:" + value);
45+
});
46+
47+
48+
}
49+
50+
/**
51+
* Random类产生随机数
52+
* @param
53+
*/
54+
public static int randFive() {
55+
Random random = new Random();
56+
int rand_five = random.nextInt(5) + 1;
57+
return rand_five;
58+
}
59+
60+
/**
61+
* Math.random()产生随机数
62+
* @param
63+
*/
64+
public static int randFiveII(int[] arr) {
65+
int max = 5, min = 1;
66+
int rand_five = (int) (Math.random() * 5 + 1);
67+
return rand_five;
68+
}
69+
70+
public static int randFiveIII() {
71+
int max = 100, min = 1;
72+
long randomNum = System.currentTimeMillis();
73+
int rand_five = (int) (randomNum % (max - min) + min);
74+
//循环同一时间会产生相同的数
75+
return rand_five;
76+
}
77+
78+
79+
/**
80+
* 调用randFive()来 等概率 产生 1-7
81+
* @return
82+
*/
83+
public static int getRandomNumSevenI() {
84+
while (true) {
85+
int randLowSeven = (randFive() - 1) * 5 + randFive();
86+
if(randLowSeven <= 21) {
87+
return randLowSeven % 7 + 1;
88+
}
89+
}
90+
}
91+
92+
93+
94+
public static int getRandomNumSevenII() {
95+
int randLowSeven = 0;
96+
while ((randLowSeven = randFive() * 5 + randFive()) > 26);
97+
98+
return (randLowSeven - 3) / 3;
99+
}
100+
101+
102+
103+
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package didipractice;
2+
3+
/**
4+
* @Author: iqqcode
5+
* @Date: 2020-10-21 14:20
6+
* @Description:
7+
*/
8+
9+
import java.util.*;
10+
11+
public class Main2 {
12+
static class ListNode {
13+
int val;
14+
ListNode next;
15+
16+
public ListNode(int val) {
17+
this.val = val;
18+
}
19+
}
20+
21+
public static void main(String[] args) {
22+
ListNode head = new ListNode(1);
23+
head.next = new ListNode(2);
24+
head.next.next = new ListNode(3);
25+
head.next.next.next = new ListNode(4);
26+
27+
ListNode node = reverse(head);
28+
while (node != null) {
29+
System.out.print(node.val + " ");
30+
node = node.next;
31+
}
32+
}
33+
34+
public static ListNode reverse(ListNode head) {
35+
if (head == null) return head;
36+
ListNode pre = null;
37+
ListNode cur = head;
38+
ListNode tmp = null;
39+
while (cur != null) {
40+
tmp = cur.next;
41+
cur.next = pre;
42+
pre = cur;
43+
cur = tmp;
44+
}
45+
return pre;
46+
}
47+
}
48+
49+
50+
51+

0 commit comments

Comments
 (0)