forked from EndlessCheng/codeforces-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa53dc1
commit f0b7bcf
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
. "fmt" | ||
"io" | ||
) | ||
|
||
// https://space.bilibili.com/206214 | ||
func CF377A(_r io.Reader, _w io.Writer) { | ||
in := bufio.NewReader(_r) | ||
out := bufio.NewWriter(_w) | ||
defer out.Flush() | ||
dir4 := []struct{ x, y int }{{-1, 0}, {1, 0}, {0, -1}, {0, 1}} | ||
|
||
var n, m, k int | ||
Fscan(in, &n, &m, &k) | ||
a := make([][]byte, n) | ||
for i := range a { | ||
Fscan(in, &a[i]) | ||
} | ||
vis := make([][]bool, n) | ||
for i := range vis { | ||
vis[i] = make([]bool, m) | ||
} | ||
var dfs func(int, int) | ||
dfs = func(i, j int) { | ||
vis[i][j] = true | ||
for _, d := range dir4 { | ||
if x, y := i+d.x, j+d.y; 0 <= x && x < n && 0 <= y && y < m && !vis[x][y] && a[x][y] == '.' { | ||
dfs(x, y) | ||
} | ||
} | ||
if k > 0 { | ||
k-- | ||
a[i][j] = 'X' | ||
} | ||
} | ||
for i, row := range a { | ||
for j, v := range row { | ||
if v == '.' { | ||
dfs(i, j) | ||
for _, r := range a { | ||
Fprintf(out, "%s\n", r) | ||
} | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
//func main() { CF377A(os.Stdin, os.Stdout) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/EndlessCheng/codeforces-go/main/testutil" | ||
"testing" | ||
) | ||
|
||
// https://codeforces.com/problemset/problem/377/A | ||
// https://codeforces.com/problemset/status/377/problem/A | ||
func TestCF377A(t *testing.T) { | ||
// just copy from website | ||
rawText := ` | ||
inputCopy | ||
3 4 2 | ||
#..# | ||
..#. | ||
#... | ||
outputCopy | ||
#.X# | ||
X.#. | ||
#... | ||
inputCopy | ||
5 4 5 | ||
#... | ||
#.#. | ||
.#.. | ||
...# | ||
.#.# | ||
outputCopy | ||
#XXX | ||
#X#. | ||
X#.. | ||
...# | ||
.#.#` | ||
testutil.AssertEqualCase(t, rawText, 0, CF377A) | ||
} |