-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path133.go
85 lines (80 loc) · 1.19 KB
/
133.go
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
// UVa 133 - The Dole Queue
package main
import (
"fmt"
"io"
"os"
"strings"
)
func solve(n, k, m int, out io.Writer) {
dole := make([]int, n)
for i := range dole {
dole[i] = i + 1
}
pk, pm := 0, n-1
outNum := 0
var outs []string
for {
for i := 1; i < k; i++ {
for {
if pk++; pk == n {
pk = 0
}
if dole[pk] != -1 {
break
}
}
}
for i := 1; i < m; i++ {
for {
if pm--; pm == -1 {
pm = n - 1
}
if dole[pm] != -1 {
break
}
}
}
if pk == pm {
outNum++
outs = append(outs, fmt.Sprintf("% 3d", dole[pk]))
} else {
outNum += 2
outs = append(outs, fmt.Sprintf("% 3d% 3d", dole[pk], dole[pm]))
}
if outNum == len(dole) {
break
}
dole[pk], dole[pm] = -1, -1
for {
if pk++; pk == n {
pk = 0
}
if dole[pk] != -1 {
break
}
}
for {
if pm--; pm == -1 {
pm = n - 1
}
if dole[pm] != -1 {
break
}
}
}
fmt.Fprintln(out, strings.Join(outs, ","))
}
func main() {
in, _ := os.Open("133.in")
defer in.Close()
out, _ := os.Create("133.out")
defer out.Close()
var n, k, m int
for {
if fmt.Fscanf(in, "%d%d%d", &n, &k, &m); n == 0 {
break
}
solve(n, k, m, out)
}
}