Created
December 1, 2019 05:12
-
-
Save SyureNyanko/f3cfa25796812056d2ab637c1883df6b to your computer and use it in GitHub Desktop.
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
package main | |
import "fmt" | |
var p = [][]string{ | |
[]string{".", ".", ".", "."}, | |
[]string{".", "W", "W", "."}, | |
[]string{"W", "W", ".", "."}, | |
[]string{"W", "W", ".", "W"}, | |
[]string{"W", "W", ".", "W"}, | |
} | |
var q = []int{0, 1, -1} | |
var w, h = len(p), len(p[0]) | |
func count(i, j int) bool { | |
if i < w && i >= 0 && j < h && j >= 0 { | |
var flag = false | |
if p[i][j] == "W" { | |
p[i][j] = "." | |
flag = true | |
} else { | |
return false | |
} | |
for _, dv := range q { | |
for _, dv2 := range q { | |
if dv == 0 && dv2 == 0 { | |
continue | |
} | |
count(i+dv, j+dv2) | |
} | |
} | |
return flag | |
} | |
return false | |
} | |
func main() { | |
c := 0 | |
for i := 0; i < w; i++ { | |
for j := 0; j < h; j++ { | |
if count(i, j) { | |
c = c + 1 | |
} | |
} | |
} | |
fmt.Println(c) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment