一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務(wù)器之家 - 編程語(yǔ)言 - JAVA教程 - Java實(shí)現(xiàn)的連續(xù)奇數(shù)(n+2*x)是合數(shù)的算法題暴力算法

Java實(shí)現(xiàn)的連續(xù)奇數(shù)(n+2*x)是合數(shù)的算法題暴力算法

2019-11-28 14:18junjie JAVA教程

這篇文章主要介紹了Java實(shí)現(xiàn)的連續(xù)奇數(shù)(n+2*x)是合數(shù)的算法題暴力算法,本文包含運(yùn)算結(jié)果和實(shí)現(xiàn)代碼,需要的朋友可以參考下

連續(xù)6個(gè)奇數(shù)a,a+2,a+4,a+6,a+8,a+10都是合數(shù),求最小的a的暴力解法。

先上結(jié)果,后面貼上代碼:

?
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
1次連續(xù)n=9,連續(xù)值個(gè)數(shù): 1;耗時(shí): 0ms,總計(jì): 0ms
2次連續(xù)n=25,連續(xù)值個(gè)數(shù): 1;耗時(shí): 0ms,總計(jì): 0ms
3次連續(xù)n=91,連續(xù)值個(gè)數(shù): 1;耗時(shí): 0ms,總計(jì): 0ms
4次連續(xù)n=115,連續(xù)值個(gè)數(shù): 3;耗時(shí): 0ms,總計(jì): 1ms
5次連續(xù)n=115,連續(xù)值個(gè)數(shù): 3;耗時(shí): 0ms,總計(jì): 1ms
6次連續(xù)n=115,連續(xù)值個(gè)數(shù): 3;耗時(shí): 0ms,總計(jì): 1ms
7次連續(xù)n=525,連續(xù)值個(gè)數(shù): 2;耗時(shí): 0ms,總計(jì): 1ms
8次連續(xù)n=525,連續(xù)值個(gè)數(shù): 2;耗時(shí): 0ms,總計(jì): 1ms
9次連續(xù)n=889,連續(xù)值個(gè)數(shù): 1;耗時(shí): 0ms,總計(jì): 1ms
10次連續(xù)n=1131,連續(xù)值個(gè)數(shù): 1;耗時(shí): 0ms,總計(jì): 1ms
11次連續(xù)n=1329,連續(xù)值個(gè)數(shù): 6;耗時(shí): 0ms,總計(jì): 1ms
12次連續(xù)n=1329,連續(xù)值個(gè)數(shù): 6;耗時(shí): 0ms,總計(jì): 1ms
13次連續(xù)n=1329,連續(xù)值個(gè)數(shù): 6;耗時(shí): 0ms,總計(jì): 1ms
14次連續(xù)n=1329,連續(xù)值個(gè)數(shù): 6;耗時(shí): 0ms,總計(jì): 1ms
15次連續(xù)n=1329,連續(xù)值個(gè)數(shù): 6;耗時(shí): 0ms,總計(jì): 1ms
16次連續(xù)n=1329,連續(xù)值個(gè)數(shù): 6;耗時(shí): 0ms,總計(jì): 1ms
17次連續(xù)n=9553,連續(xù)值個(gè)數(shù): 1;耗時(shí): 2ms,總計(jì): 3ms
18次連續(xù)n=15685,連續(xù)值個(gè)數(shù): 4;耗時(shí): 1ms,總計(jì): 5ms
19次連續(xù)n=15685,連續(xù)值個(gè)數(shù): 4;耗時(shí): 1ms,總計(jì): 5ms
20次連續(xù)n=15685,連續(xù)值個(gè)數(shù): 4;耗時(shí): 1ms,總計(jì): 5ms
21次連續(xù)n=15685,連續(xù)值個(gè)數(shù): 4;耗時(shí): 1ms,總計(jì): 5ms
22次連續(xù)n=19611,連續(xù)值個(gè)數(shù): 4;耗時(shí): 2ms,總計(jì): 8ms
23次連續(xù)n=19611,連續(xù)值個(gè)數(shù): 4;耗時(shí): 2ms,總計(jì): 8ms
24次連續(xù)n=19611,連續(xù)值個(gè)數(shù): 4;耗時(shí): 2ms,總計(jì): 8ms
25次連續(xù)n=19611,連續(xù)值個(gè)數(shù): 4;耗時(shí): 2ms,總計(jì): 8ms
26次連續(xù)n=31399,連續(xù)值個(gè)數(shù): 10;耗時(shí): 5ms,總計(jì): 13ms
27次連續(xù)n=31399,連續(xù)值個(gè)數(shù): 10;耗時(shí): 5ms,總計(jì): 13ms
28次連續(xù)n=31399,連續(xù)值個(gè)數(shù): 10;耗時(shí): 5ms,總計(jì): 13ms
29次連續(xù)n=31399,連續(xù)值個(gè)數(shù): 10;耗時(shí): 5ms,總計(jì): 13ms
30次連續(xù)n=31399,連續(xù)值個(gè)數(shù): 10;耗時(shí): 5ms,總計(jì): 13ms
31次連續(xù)n=31399,連續(xù)值個(gè)數(shù): 10;耗時(shí): 5ms,總計(jì): 13ms
32次連續(xù)n=31399,連續(xù)值個(gè)數(shù): 10;耗時(shí): 5ms,總計(jì): 13ms
33次連續(xù)n=31399,連續(xù)值個(gè)數(shù): 10;耗時(shí): 5ms,總計(jì): 13ms
34次連續(xù)n=31399,連續(xù)值個(gè)數(shù): 10;耗時(shí): 5ms,總計(jì): 13ms
35次連續(xù)n=31399,連續(xù)值個(gè)數(shù): 10;耗時(shí): 5ms,總計(jì): 13ms
36次連續(xù)n=155923,連續(xù)值個(gè)數(shù): 7;耗時(shí): 92ms,總計(jì): 105ms
37次連續(xù)n=155923,連續(xù)值個(gè)數(shù): 7;耗時(shí): 92ms,總計(jì): 105ms
38次連續(xù)n=155923,連續(xù)值個(gè)數(shù): 7;耗時(shí): 92ms,總計(jì): 105ms
39次連續(xù)n=155923,連續(xù)值個(gè)數(shù): 7;耗時(shí): 92ms,總計(jì): 105ms
40次連續(xù)n=155923,連續(xù)值個(gè)數(shù): 7;耗時(shí): 92ms,總計(jì): 105ms
41次連續(xù)n=155923,連續(xù)值個(gè)數(shù): 7;耗時(shí): 92ms,總計(jì): 105ms
42次連續(xù)n=155923,連續(xù)值個(gè)數(shù): 7;耗時(shí): 93ms,總計(jì): 106ms
43次連續(xù)n=360655,連續(xù)值個(gè)數(shù): 5;耗時(shí): 243ms,總計(jì): 349ms
44次連續(xù)n=360655,連續(xù)值個(gè)數(shù): 5;耗時(shí): 243ms,總計(jì): 349ms
45次連續(xù)n=360655,連續(xù)值個(gè)數(shù): 5;耗時(shí): 243ms,總計(jì): 349ms
46次連續(xù)n=360655,連續(xù)值個(gè)數(shù): 5;耗時(shí): 243ms,總計(jì): 349ms
47次連續(xù)n=360655,連續(xù)值個(gè)數(shù): 5;耗時(shí): 243ms,總計(jì): 349ms
48次連續(xù)n=370263,連續(xù)值個(gè)數(shù): 8;耗時(shí): 14ms,總計(jì): 363ms
49次連續(xù)n=370263,連續(xù)值個(gè)數(shù): 8;耗時(shí): 14ms,總計(jì): 363ms
50次連續(xù)n=370263,連續(xù)值個(gè)數(shù): 8;耗時(shí): 14ms,總計(jì): 363ms
51次連續(xù)n=370263,連續(xù)值個(gè)數(shù): 8;耗時(shí): 14ms,總計(jì): 363ms
52次連續(xù)n=370263,連續(xù)值個(gè)數(shù): 8;耗時(shí): 14ms,總計(jì): 363ms
53次連續(xù)n=370263,連續(xù)值個(gè)數(shù): 8;耗時(shí): 14ms,總計(jì): 363ms
54次連續(xù)n=370263,連續(xù)值個(gè)數(shù): 8;耗時(shí): 14ms,總計(jì): 363ms
55次連續(xù)n=370263,連續(xù)值個(gè)數(shù): 8;耗時(shí): 14ms,總計(jì): 363ms
56次連續(xù)n=492115,連續(xù)值個(gè)數(shù): 1;耗時(shí): 185ms,總計(jì): 548ms
57次連續(xù)n=1349535,連續(xù)值個(gè)數(shù): 2;耗時(shí): 1854ms,總計(jì): 2402ms
58次連續(xù)n=1349535,連續(xù)值個(gè)數(shù): 2;耗時(shí): 1854ms,總計(jì): 2402ms
59次連續(xù)n=1357203,連續(xù)值個(gè)數(shù): 7;耗時(shí): 22ms,總計(jì): 2424ms
60次連續(xù)n=1357203,連續(xù)值個(gè)數(shù): 7;耗時(shí): 22ms,總計(jì): 2424ms
61次連續(xù)n=1357203,連續(xù)值個(gè)數(shù): 7;耗時(shí): 22ms,總計(jì): 2424ms
62次連續(xù)n=1357203,連續(xù)值個(gè)數(shù): 7;耗時(shí): 22ms,總計(jì): 2424ms
63次連續(xù)n=1357203,連續(xù)值個(gè)數(shù): 7;耗時(shí): 22ms,總計(jì): 2424ms
64次連續(xù)n=1357203,連續(xù)值個(gè)數(shù): 7;耗時(shí): 22ms,總計(jì): 2424ms
65次連續(xù)n=1357203,連續(xù)值個(gè)數(shù): 7;耗時(shí): 22ms,總計(jì): 2424ms
66次連續(xù)n=2010735,連續(xù)值個(gè)數(shù): 8;耗時(shí): 1889ms,總計(jì): 4313ms
67次連續(xù)n=2010735,連續(xù)值個(gè)數(shù): 8;耗時(shí): 1889ms,總計(jì): 4313ms
68次連續(xù)n=2010735,連續(xù)值個(gè)數(shù): 8;耗時(shí): 1889ms,總計(jì): 4313ms
69次連續(xù)n=2010735,連續(xù)值個(gè)數(shù): 8;耗時(shí): 1889ms,總計(jì): 4313ms
70次連續(xù)n=2010735,連續(xù)值個(gè)數(shù): 8;耗時(shí): 1889ms,總計(jì): 4313ms
71次連續(xù)n=2010735,連續(xù)值個(gè)數(shù): 8;耗時(shí): 1889ms,總計(jì): 4313ms
72次連續(xù)n=2010735,連續(xù)值個(gè)數(shù): 8;耗時(shí): 1889ms,總計(jì): 4313ms
73次連續(xù)n=2010735,連續(xù)值個(gè)數(shù): 8;耗時(shí): 1890ms,總計(jì): 4314ms
74次連續(xù)n=4652355,連續(xù)值個(gè)數(shù): 3;耗時(shí): 10583ms,總計(jì): 14897ms
75次連續(xù)n=4652355,連續(xù)值個(gè)數(shù): 3;耗時(shí): 10583ms,總計(jì): 14897ms
76次連續(xù)n=4652355,連續(xù)值個(gè)數(shù): 3;耗時(shí): 10583ms,總計(jì): 14897ms
77次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86082ms,總計(jì): 100979ms
78次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86082ms,總計(jì): 100979ms
79次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86082ms,總計(jì): 100979ms
80次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86082ms,總計(jì): 100979ms
81次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86082ms,總計(jì): 100979ms
82次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86082ms,總計(jì): 100979ms
83次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86082ms,總計(jì): 100979ms
84次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86082ms,總計(jì): 100979ms
85次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86083ms,總計(jì): 100980ms
86次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86083ms,總計(jì): 100980ms
87次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86083ms,總計(jì): 100980ms
88次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86083ms,總計(jì): 100980ms
89次連續(xù)n=17051709,連續(xù)值個(gè)數(shù): 13;耗時(shí): 86083ms,總計(jì): 100980ms
90次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34772ms,總計(jì): 135752ms
91次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34772ms,總計(jì): 135752ms
92次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34772ms,總計(jì): 135752ms
93次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34772ms,總計(jì): 135752ms
94次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34772ms,總計(jì): 135752ms
95次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34772ms,總計(jì): 135752ms
96次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34772ms,總計(jì): 135752ms
97次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34772ms,總計(jì): 135752ms
98次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34772ms,總計(jì): 135752ms
99次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34773ms,總計(jì): 135753ms
100次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34773ms,總計(jì): 135753ms
101次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34773ms,總計(jì): 135753ms
102次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34773ms,總計(jì): 135753ms
103次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34773ms,總計(jì): 135753ms
104次連續(xù)n=20831325,連續(xù)值個(gè)數(shù): 15;耗時(shí): 34773ms,總計(jì): 135753ms
105次連續(xù)n=47326695,連續(xù)值個(gè)數(shù): 5;耗時(shí): 319130ms,總計(jì): 452155ms
106次連續(xù)n=47326695,連續(xù)值個(gè)數(shù): 5;耗時(shí): 319131ms,總計(jì): 452156ms
107次連續(xù)n=47326695,連續(xù)值個(gè)數(shù): 5;耗時(shí): 319131ms,總計(jì): 452156ms
108次連續(xù)n=47326695,連續(xù)值個(gè)數(shù): 5;耗時(shí): 319131ms,總計(jì): 452156ms
109次連續(xù)n=47326695,連續(xù)值個(gè)數(shù): 5;耗時(shí): 319131ms,總計(jì): 452156ms
110次連續(xù)n=122164749,連續(xù)值個(gè)數(shù): 1;耗時(shí): 1395200ms,總計(jì): 1847356ms
111次連續(xù)n=189695661,連續(xù)值個(gè)數(shù): 6;耗時(shí): 1705936ms,總計(jì): 3553292ms
112次連續(xù)n=189695661,連續(xù)值個(gè)數(shù): 6;耗時(shí): 1705936ms,總計(jì): 3553292ms
113次連續(xù)n=189695661,連續(xù)值個(gè)數(shù): 6;耗時(shí): 1705936ms,總計(jì): 3553292ms
114次連續(xù)n=189695661,連續(xù)值個(gè)數(shù): 6;耗時(shí): 1705936ms,總計(jì): 3553292ms
115次連續(xù)n=189695661,連續(xù)值個(gè)數(shù): 6;耗時(shí): 1705936ms,總計(jì): 3553292ms
116次連續(xù)n=189695661,連續(xù)值個(gè)數(shù): 6;耗時(shí): 1705936ms,總計(jì): 3553292ms
117次連續(xù)n=191912785,連續(xù)值個(gè)數(shù): 7;耗時(shí): 61964ms,總計(jì): 3615256ms
118次連續(xù)n=191912785,連續(xù)值個(gè)數(shù): 7;耗時(shí): 61964ms,總計(jì): 3615256ms
119次連續(xù)n=191912785,連續(xù)值個(gè)數(shù): 7;耗時(shí): 61964ms,總計(jì): 3615256ms
120次連續(xù)n=191912785,連續(xù)值個(gè)數(shù): 7;耗時(shí): 61964ms,總計(jì): 3615256ms
121次連續(xù)n=191912785,連續(xù)值個(gè)數(shù): 7;耗時(shí): 61964ms,總計(jì): 3615256ms
122次連續(xù)n=191912785,連續(xù)值個(gè)數(shù): 7;耗時(shí): 61964ms,總計(jì): 3615256ms
123次連續(xù)n=191912785,連續(xù)值個(gè)數(shù): 7;耗時(shí): 61964ms,總計(jì): 3615256ms
124次連續(xù)n=387096135,連續(xù)值個(gè)數(shù): 1;耗時(shí): 6650201ms,總計(jì): 10265457ms
-----
本次已經(jīng)跑完了,下一個(gè)值超出了1000次;無(wú)用耗時(shí): 0ms,總計(jì): xxxxxx135395ms

。。。。。。 后面的結(jié)果還沒(méi)算出來(lái)

代碼如下所示:

?
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package com.test.test.zhihe;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
/**
 * 連續(xù)6個(gè)奇數(shù)a,a+2,a+4,a+6,a+8,a+10都是合數(shù),求最小的a
 */
public class ZhishuTest {
 /**
 * 判斷某個(gè)數(shù)是否是合數(shù). 相較于質(zhì)數(shù)
 * @param num
 * @return
 */
 public static boolean He(int num){
 // 平方根
 int sq = ((Double)Math.sqrt(num)).intValue();
 // 2 ...... sq
 for (int i = 2; i <= sq; i++) {
  int mo = num % i;
  if(0 == mo){
  return true;
  }
 }
 //
 return false;
 }
 
 /**
 * 主函數(shù)
 * @param args
 */
 public static void main(String[] args) {
 test();
 }
 public static void test() {
 // 開(kāi)始時(shí)間
 long startMillis = System.currentTimeMillis();
 // 上次完成時(shí)間
 long preMillis = System.currentTimeMillis();
 // 本次完成時(shí)間
 long curMillis = System.currentTimeMillis();
 //
 int lianxu = 1000;
 int start = 1;
 int times = 1;
 for (int x = 1; x <= lianxu; x++) {
  if(times > x){
  continue;// 跳過(guò),進(jìn)入下一次循環(huán)
  } else {
  times = x;
  }
  List<Map<Integer, Integer>> resList = testTimesHe(x, start, false);
  //
  // 如果有數(shù)字,則進(jìn)行處理
  if(null == resList || resList.isEmpty()){
  // 找不到,就不會(huì)再有下一個(gè)了...
  // 深層嵌套太惡心了。。。
  break;
  }
  int size = resList.size();
  // 遍歷
  Iterator<Map<Integer, Integer>> iteratorR = resList.iterator();
  while (iteratorR.hasNext()) {
  Map<Integer, Integer> map = (Map<Integer, Integer>) iteratorR.next();
  //
  if(null != map && !map.isEmpty()){
   // Map遍歷太惡心了.爛Java
   Set<Integer> keys= map.keySet();
   Iterator<Integer> iteratorK = keys.iterator();
   if(iteratorK.hasNext()){
   Integer key = iteratorK.next(); // 次數(shù)
   Integer value = map.get(key); // 最小n
   //
   // 本次完成時(shí)間
   curMillis = System.currentTimeMillis();
   //
   long allTimeout = curMillis - startMillis;
   long curTimeout = curMillis - preMillis;
   System.out.println(""+key+"次連續(xù)n="+value +",連續(xù)值個(gè)數(shù): "+size +
    ";耗時(shí): " + curTimeout + "ms,總計(jì): "+allTimeout+"ms");
   // 處理數(shù)據(jù),貪婪處理過(guò)的就不處理了
   if(key > 0 && value > 0){
    times = key+1;
    start = value;
   }
   }
  }
  }
  // 計(jì)入上次完成時(shí)間
  preMillis = System.currentTimeMillis();
 }
 //
 // 本次完成時(shí)間
 curMillis = System.currentTimeMillis();
 //
 long allTimeout = curMillis - startMillis;
 long curTimeout = curMillis - preMillis;
 System.out.println("本次已經(jīng)跑完了,下一個(gè)值超出了100次 " +
  ";無(wú)用耗時(shí): " + curTimeout + "ms,總計(jì): "+allTimeout+"ms");
 }
 
 
 /**
 *
 * 測(cè)試 times 次的+2都是合數(shù)的最小n
 * @param times 計(jì)算次數(shù)
 * @param start 起始數(shù)字
 * @param onlyStart 只計(jì)算單個(gè)start值.用于遞歸.外部調(diào)用應(yīng)該傳入
 * @return
 */
 public static List<Map<Integer, Integer>> testTimesHe(int times,int start, boolean onlyStart) {
 //
 List<Map<Integer, Integer>> resList= new ArrayList<Map<Integer, Integer>>();
 //
 // 防御式編程
 if(start < 1){
  return resList;
 }
 if(0 == start % 2){ // 不處理偶數(shù)
  return resList;
 }
 if(times < 1){
  times = 1;
 }
 //
 int result = -1;
 //
 for (int i = start; i < Integer.MAX_VALUE; i+=2) {
  //
  // 避免一直計(jì)算不返回
  if(onlyStart && i > start){ // start 不滿(mǎn)足,就直接
  return resList;
  }
  for (int j = 0; j < times; j++) {
  int n = i + 2*j;
  //
  if(!He(n)){
   break;// 內(nèi)層退出
  }
  //
  if(j+1 == times){
   // 跑到結(jié)果了. times 次都滿(mǎn)足
   result = i;
   break;// 這里退不退無(wú)所謂,跑到for的最后了
  }
  }
  //
  if(result > 0){
  //
  //System.out.println("result = "+result);
  //
  Map<Integer, Integer> resMap = new HashMap<Integer, Integer>();
  resMap.put(times, result);
  resList.add(resMap);
  // 嘗試下一個(gè)次數(shù),遞歸; 其實(shí)這個(gè)遞歸還可以繼續(xù)優(yōu)化一點(diǎn); 貪婪算法,直接加下一次。。。
  // startTimes, 直接加這個(gè)參數(shù)。。。貪婪遞歸?
  // 多1次,從result這個(gè)數(shù)開(kāi)始
  int t = times +1;
  int s = result;
  List<Map<Integer, Integer>> nextList = testTimesHe(t, s, true);
  // 如果有下一層的數(shù)字,則加入到當(dāng)前結(jié)果
  if(null != nextList && false==nextList.isEmpty()){
   resList.addAll(nextList);
  }
  
  //
  break;// 外層退出
  }
 }
 //
 return resList;
 }
}

說(shuō)明: 還有改進(jìn)空間,歡迎下次修正

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 香港日本三级亚洲三级 | 日本道色综合久久影院 | 草莓视频丝瓜 | 动漫美女被吸乳羞羞小说 | 亚洲欧美日韩另类精品一区二区三区 | 日本精a在线观看 | 欧美又硬又粗又长又大 | 久久视频这有精品63在线国产 | 亚洲第一福利视频 | 国产精品人人视频 | 桃子视频www | 视频亚洲一区 | 99久久精品免费看国产 | 美女裆部| 九色PORNY真实丨国产大胸 | 亚欧综合| 男人使劲躁女人小视频 | 四虎黄色影视 | 亚洲AV无码乱码国产麻豆穿越 | 国内自拍网红在线自拍综合 | 成人在线播放视频 | 丝瓜视频成人在线观看 | 精品伊人 | 婷婷在线综合 | 日本 片 成人 在线 日b视频免费 | 51午夜| 欧洲女同同性videos0 | 星球大战成人h无删减版 | 四虎影视库永久在线地址 | 91综合精品网站久久 | 双性鞭蒂软汁淋漓 | 午夜国产理论 | chinese男男gayxxx chinese老头和老太交hd | 温柔校草高h | 亚洲精品成人a | 麻豆视频免费在线观看 | 午夜影院在线免费观看 | 女人国产香蕉久久精品 | 日韩免费毛片视频杨思敏 | 好深快点再快点好爽视频 | 成人中文字幕在线观看 |