-
Notifications
You must be signed in to change notification settings - Fork 577
/
main.go
105 lines (83 loc) · 1.91 KB
/
main.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"bufio"
. "fmt"
"os"
)
// https://space.bilibili.com/206214
type interaction interface {
readInitData() initData
query(request) response
printAnswer(answer)
}
type stdIO struct {
in *bufio.Reader
out *bufio.Writer
}
type (
initData struct{ n int }
request struct{ q int }
response struct{ v int } // 如果有多种不同类型的返回值,改成 string 或者 []any
answer struct{ ans int }
)
func (io stdIO) readInitData() initData {
in := io.in
var n int
Fscan(in, &n)
// TODO 初始输入格式?
return initData{n}
}
func (io stdIO) query(q request) (resp response) {
in, out := io.in, io.out
Fprintln(out, "?", q.q)
//Fprint(out, "?")
//Fprint(out, " ", len(q.q)) // TODO 输出 query 长度?
//for _, v := range q.q { Fprint(out, " ", v) }
//Fprintln(out)
out.Flush()
Fscan(in, &resp.v)
//if resp.v < 0 { panic(-1) }
return
}
func (io stdIO) printAnswer(a answer) {
out := io.out
Fprintln(out, "!", a.ans)
//Fprint(out, "!")
//Fprint(out, " ", len(a.ans)) // TODO 输出答案长度?
//for _, v := range a.ans { Fprint(out, " ", v) }
//Fprintln(out)
out.Flush()
// TODO judge 是否返回答案非法?(通常是 move on to the next test case)
//var state int
//Fscan(io.in, &state)
//if state < 0 { panic(state) }
}
func doInteraction(it interaction) {
// TODO 初始输入格式?
dt := it.readInitData()
n := dt.n
_ = n
// TODO query 格式?
get := func(q int) int {
//for i := range q { q[i]++ }
return it.query(request{q}).v
}
_ = get
// TODO 答案类型?
var ans int
//ans := make([]int, n)
defer func() { it.printAnswer(answer{ans}) }()
// TODO: 在这里实现
}
// TODO: 运行 & 测试!检查格式是否正确
func main() { run() }
func run() {
in := bufio.NewReader(os.Stdin)
out := bufio.NewWriter(os.Stdout)
T := 1
// TODO:多测?
Fscan(in, &T)
for ; T > 0; T-- {
doInteraction(stdIO{in, out})
}
}