Skip to content

Commit 62ec5c1

Browse files
committed
#0923 commit
1 parent 91fd26e commit 62ec5c1

File tree

8 files changed

+252
-6
lines changed

8 files changed

+252
-6
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.blankj.study.singleton;
2+
3+
public enum EnumSingleton {
4+
INSTANCE;
5+
6+
public EnumSingleton getInstance() {
7+
return INSTANCE;
8+
}
9+
}

src/com/blankj/study/singleton/HungrySingleton.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ public class HungrySingleton {
55
private HungrySingleton() {
66
}
77

8-
;
9-
108
private static final HungrySingleton instance = new HungrySingleton();
119

1210
public static HungrySingleton getInstance() {

src/com/blankj/study/singleton/InnerSingleton.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ public class InnerSingleton {
66
private InnerSingleton() {
77
}
88

9-
;
10-
119
public static InnerSingleton getInstance() {
1210
return SingletonHolder.instance;
1311
}

src/com/blankj/study/singleton/LazySingleton.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ public class LazySingleton {
66
private LazySingleton() {
77
}
88

9-
;
10-
119
private static volatile LazySingleton instance = null;
1210

1311
public static LazySingleton getInstance() {

src/com/blankj/study/temp/Test06.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.blankj.study.temp;
2+
3+
import java.util.Arrays;
4+
5+
public class Test06 {
6+
7+
public static void main(String[] args) {
8+
int[] arr = new int[]{1, 5, 6, 8, 45, 2, 34, 5};
9+
System.out.println(Arrays.toString(arr));
10+
quickSort(arr, 0, arr.length - 1);
11+
System.out.println(Arrays.toString(arr));
12+
}
13+
14+
public static void quickSort(int[] arrs, int left, int right) {
15+
if (left > right) {
16+
return;
17+
}
18+
19+
int i, j, temp, t;
20+
i = left;
21+
j = right;
22+
temp = arrs[i];
23+
24+
while (i < j) {
25+
while (temp <= arrs[j] && i < j) {
26+
j--;
27+
}
28+
while (temp >= arrs[i] && i < j) {
29+
i++;
30+
}
31+
32+
if (i < j) {
33+
t = arrs[i];
34+
arrs[i] = arrs[j];
35+
arrs[j] = t;
36+
}
37+
}
38+
39+
arrs[left] = arrs[i];
40+
arrs[i] = temp;
41+
42+
quickSort(arrs, left, j - 1);
43+
quickSort(arrs, j + 1, right);
44+
}
45+
}

src/com/blankj/study/temp/Test07.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.blankj.study.temp;
2+
3+
4+
import java.util.ArrayList;
5+
import java.util.Iterator;
6+
import java.util.List;
7+
import java.util.Scanner;
8+
9+
public class Test07 {
10+
private static String s;
11+
private static String d[];
12+
private static List<int[]> resultList;
13+
14+
public static void fun(int i, int[] check, String current) {
15+
if (current.length() == 0) {
16+
int checkd[] = new int[check.length];
17+
for (int j = 0; j < check.length; j++) {
18+
checkd[j] = check[j];
19+
}
20+
resultList.add(checkd);
21+
return;
22+
}
23+
if (i >= d.length) {
24+
return;
25+
}
26+
//判断是否需要进入左子树
27+
int sumLength = 0;
28+
//求出剩余子集中字符串的长度
29+
for (int j = i + 1; j < d.length; j++) {
30+
sumLength += d[j].length();
31+
}
32+
if (current.length() <= sumLength) {
33+
//可以进入左子树
34+
int cTemp = check[i];
35+
check[i] = 0;
36+
fun(i + 1, check, current);
37+
//回溯
38+
check[i] = cTemp;
39+
}
40+
41+
//判断是否可以进入右子树
42+
if (current.indexOf(d[i]) != -1) {
43+
String cuTemp = current;
44+
current = current.substring(0, current.indexOf(d[i])) + current.substring(current.indexOf(d[i]) + d[i].length());
45+
int cTemp = check[i];
46+
check[i] = 1;
47+
fun(i + 1, check, current);
48+
//回溯
49+
check[i] = cTemp;
50+
current = cuTemp;
51+
}
52+
}
53+
54+
public static void main(String args[]) {
55+
Scanner scan = new Scanner(System.in);
56+
s = scan.nextLine();
57+
s = s.substring(s.indexOf("\"") + 1, s.lastIndexOf("\""));
58+
String dict = scan.nextLine();
59+
dict = dict.substring(dict.indexOf("=") + 1);
60+
d = dict.split(",");
61+
for (int i = 0; i < d.length; i++) {
62+
d[i] = d[i].substring(d[i].indexOf("\"") + 1, d[i].lastIndexOf("\""));
63+
}
64+
int[] check = new int[d.length];
65+
for (int i = 0; i < check.length; i++) {
66+
check[i] = -1;
67+
}
68+
String current = s;
69+
resultList = new ArrayList<int[]>();
70+
fun(0, check, current);
71+
72+
System.out.print("[");
73+
//将对结果集中的结果进行处理
74+
Iterator iter = resultList.iterator();
75+
int size = resultList.size();
76+
int count = 0;
77+
while (iter.hasNext()) {
78+
79+
String sTemp = new String(s);
80+
int[] p = (int[]) iter.next();
81+
for (int i = 0; i < p.length; i++) {
82+
if (p[i] == 1) {
83+
int index = sTemp.indexOf(d[i]) + d[i].length();
84+
if (index != sTemp.length()) {
85+
String sTemp1 = sTemp.substring(0, index);
86+
String sTemp2 = sTemp.substring(index);
87+
sTemp = sTemp1 + " " + sTemp2;
88+
}
89+
}
90+
}
91+
System.out.print(sTemp);
92+
if (count < size - 1) {
93+
System.out.print(", ");
94+
count++;
95+
}
96+
}
97+
System.out.print("]");
98+
}
99+
}
100+
101+

src/com/blankj/study/temp/Test08.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.blankj.study.temp;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.Scanner;
6+
7+
public class Test08 {
8+
public static void main(String[] args) {
9+
Scanner scanner = new Scanner(System.in);
10+
int n = scanner.nextInt();
11+
ArrayList<int[]> list = new ArrayList<>();
12+
for (int i = 0; i < n; i++) {
13+
int k = scanner.nextInt();
14+
int in[] = new int[k];
15+
for (int j = 0; j < k; j++) {
16+
in[j] = scanner.nextInt();
17+
}
18+
list.add(in);
19+
}
20+
for (int[] ints : list) {
21+
resolve(ints);
22+
}
23+
}
24+
25+
public static void resolve(int[] m) {
26+
int[] dp = new int[m.length];
27+
dp[0] = 1;
28+
for (int i = 1; i <= m.length - 1; i++) {
29+
int x = sum(m, i);
30+
int temp = dp[i - 1] + 1;
31+
dp[i] = (m[i] >= x ? temp : 1);
32+
}
33+
Arrays.sort(dp);
34+
35+
System.out.println(dp[m.length - 1]);
36+
37+
}
38+
39+
public static int sum(int[] k, int index) {
40+
int temp = 0;
41+
for (int i = index - 1; i >= 0; i--) {
42+
if (i - 1 > 0) {
43+
if (k[i - 1] >= k[1])
44+
break;
45+
}
46+
temp += k[i];
47+
}
48+
return temp;
49+
}
50+
}

src/com/blankj/study/temp/Test09.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.blankj.study.temp;
2+
3+
public class Test09 {
4+
//尝试使用动态规划解决,分为6种情况
5+
public static int checkRecord(int n) {
6+
//boundary conditions
7+
if (n == 0)
8+
return 0;
9+
if (n == 1)
10+
return 3;
11+
if (n == 2)
12+
return 8;
13+
14+
//下面至少3个连续的评价
15+
//INIT
16+
long[][] dp = new long[n + 1][6];
17+
int max = 1000000007;
18+
int index = 3;
19+
20+
dp[2][0] = 1;//含有A,且以L结尾
21+
dp[2][1] = 0;//含有A,且以LL结尾
22+
dp[2][2] = 3;//含有A的其他情况
23+
24+
dp[2][3] = 1;//不含有A,且以L结尾
25+
dp[2][4] = 1;//不含有A,且以LL结尾
26+
dp[2][5] = 2;//不含有A的其他情况
27+
28+
29+
while (index <= n) {
30+
dp[index][0] = dp[index - 1][2] % max;
31+
dp[index][1] = dp[index - 1][0] % max;
32+
dp[index][2] = (dp[index - 1][0] + dp[index - 1][1] + dp[index - 1][2] + dp[index - 1][3] + dp[index - 1][4] + dp[index - 1][5]) % max;
33+
34+
dp[index][3] = dp[index - 1][5] % max;
35+
dp[index][4] = dp[index - 1][3] % max;
36+
dp[index][5] = (dp[index - 1][3] + dp[index - 1][4] + dp[index - 1][5]) % max;
37+
38+
index++;
39+
}
40+
41+
return (int) ((dp[n][0] + dp[n][1] + dp[n][2] + dp[n][3] + dp[n][4] + dp[n][5]) % max);
42+
}
43+
44+
public static void main(String[] args) {
45+
System.out.println(checkRecord(2));
46+
}
47+
}

0 commit comments

Comments
 (0)