-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkindex.go
More file actions
77 lines (70 loc) · 1.94 KB
/
Copy pathkindex.go
File metadata and controls
77 lines (70 loc) · 1.94 KB
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
package gocache
import (
"time"
)
var array = [][]int64{
{462, 428, 420, 409, 398, 357, 350, 319, 314, 307, 305, 299, 288, 224, 200},
{446, 412, 402, 401, 384, 319, 309, 302, 291, 289, 283, 281, 244, 210, 176},
{405, 387, 361, 361, 351, 291, 280, 274, 268, 268, 261, 241, 233, 195, 163},
{380, 364, 334, 330, 312, 267, 266, 254, 252, 237, 232, 204, 194, 156, 145},
{346, 344, 325, 322, 292, 248, 230, 230, 223, 212, 197, 189, 144, 130, 118},
{323, 315, 280, 278, 258, 205, 201, 201, 199, 181, 175, 162, 110, 98, 92},
{287, 270, 266, 237, 208, 193, 192, 175, 161, 140, 135, 133, 104, 76, 54},
{265, 239, 232, 229, 187, 167, 161, 140, 125, 111, 101, 98, 76, 47, 45},
{254, 216, 201, 183, 146, 138, 132, 125, 95, 88, 70, 69, 52, 14, 5},
{219, 183, 179, 178, 104, 99, 96, 92, 83, 75, 34, 32, 27},
{209, 166, 150, 146, 87, 82, 73, 65, 52, 26, 12, 5, 4, 3},
{196, 151, 132, 114, 72, 67, 47, 47, 46, 45, 44, 43, 40, 39, 38},
{171, 115, 90, 81, 59, 27, 25, 12, 7, 6, 5, 4, 3, 2, 1},
{129, 79, 56, 52, 36, 20, 19, 18, 17, 16, 13, 12, 7, 3, 1},
{87, 32, 25, 15, 12, 10, 9, 8, 7, 6, 5, 4, 3, 2},
{49, 43, 23, 21, 20, 18, 15, 14, 11, 10, 9, 6, 3, 2, 1},
}
type node struct {
x, y int
val int64
}
func run() {
result := make([]int64, 0)
indexs := make([]int, len(array))
m := make(map[int64]struct{})
for {
max := node{}
for i := range indexs {
if indexs[i] == -1 {
continue
}
if array[i][indexs[i]] > max.val {
max.val = array[i][indexs[i]]
max.x = i
max.y = indexs[i]
}
}
if len(array[max.x]) == max.y+1 {
// 如果是最后一个
indexs[max.x] = -1
} else {
indexs[max.x] = max.y + 1
}
if _, ok := m[max.val]; ok {
time.Sleep(time.Second)
continue
}
m[max.val] = struct{}{}
result = append(result, max.val)
if len(result) >= 100 {
return
}
finished := true
for _, v := range indexs {
if v != -1 {
finished = false
continue
}
}
if !finished {
continue
}
return
}
}