Skip to content

Commit 8d69e77

Browse files
committed
[1800] CF1063B 结论题 01BFS
1 parent 71710b7 commit 8d69e77

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

main/1000-1099/1063B.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
type pair63 struct{ x, y, l, r int }
11+
type deque63 struct{ l, r []pair63 }
12+
13+
func (q deque63) empty() bool { return len(q.l) == 0 && len(q.r) == 0 }
14+
func (q *deque63) pushL(v pair63) { q.l = append(q.l, v) }
15+
func (q *deque63) pushR(v pair63) { q.r = append(q.r, v) }
16+
func (q *deque63) popL() (v pair63) {
17+
if len(q.l) > 0 {
18+
q.l, v = q.l[:len(q.l)-1], q.l[len(q.l)-1]
19+
} else {
20+
v, q.r = q.r[0], q.r[1:]
21+
}
22+
return
23+
}
24+
25+
func CF1063B(_r io.Reader, out io.Writer) {
26+
in := bufio.NewReader(_r)
27+
dir4 := []struct{ x, y, l, r int }{{x: -1}, {x: 1}, {0, -1, 1, 0}, {0, 1, 0, 1}}
28+
29+
var n, m, sx, sy, ll, rr, ans int
30+
Fscan(in, &n, &m, &sx, &sy, &ll, &rr)
31+
sx--
32+
sy--
33+
g := make([][]byte, n)
34+
for i := range g {
35+
Fscan(in, &g[i])
36+
}
37+
38+
q := deque63{}
39+
q.pushL(pair63{sx, sy, 0, 0})
40+
g[sx][sy] = 0
41+
for !q.empty() {
42+
ans++
43+
p := q.popL()
44+
for _, d := range dir4 {
45+
x, y, l, r := p.x+d.x, p.y+d.y, p.l+d.l, p.r+d.r
46+
if 0 <= x && x < n && 0 <= y && y < m && l <= ll && r <= rr && g[x][y] == '.' {
47+
g[x][y] = 0
48+
p := pair63{x, y, l, r}
49+
if d.y == 0 {
50+
q.pushL(p)
51+
} else {
52+
q.pushR(p)
53+
}
54+
}
55+
}
56+
}
57+
Fprint(out, ans)
58+
}
59+
60+
//func main() { CF1063B(os.Stdin, os.Stdout) }

main/1000-1099/1063B_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"github.com/EndlessCheng/codeforces-go/main/testutil"
5+
"testing"
6+
)
7+
8+
// https://codeforces.com/problemset/problem/1063/B
9+
// https://codeforces.com/problemset/status/1063/problem/B
10+
func TestCF1063B(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
4 5
15+
3 2
16+
1 2
17+
.....
18+
.***.
19+
...**
20+
*....
21+
outputCopy
22+
10
23+
inputCopy
24+
4 4
25+
2 2
26+
0 1
27+
....
28+
..*.
29+
....
30+
....
31+
outputCopy
32+
7`
33+
testutil.AssertEqualCase(t, rawText, 0, CF1063B)
34+
}

0 commit comments

Comments
 (0)