From 604599290e7f82169121b483c520d28f81ca324e Mon Sep 17 00:00:00 2001 From: 0xff-dev Date: Thu, 21 Nov 2024 09:19:46 +0800 Subject: [PATCH] Add solution and test-cases for problem 2257 --- .../1.png | Bin 0 -> 17896 bytes .../2.png | Bin 0 -> 8198 bytes .../README.md | 33 ++++---- .../Solution.go | 77 +++++++++++++++++- .../Solution_test.go | 22 ++--- 5 files changed, 105 insertions(+), 27 deletions(-) create mode 100644 leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/1.png create mode 100644 leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/2.png diff --git a/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/1.png b/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/1.png new file mode 100644 index 0000000000000000000000000000000000000000..1ca001435dab36fe37eb7bf3a847731ada89c776 GIT binary patch literal 17896 zcmeIac|6qJ`#)aY-DRmzNs(;H9a)D#_OXn8A7csGW-w-KvoJynDHTbPgyvQWA%qZ$ zB-y59H>5067~5oDerM>u@Av)wyzk%lpYP-GeSE)Iq)92V28o+wxnFe%rQf_iMbqJsul^ z^6~T9CJxcvdMByJM96Nd{&f zpufHj;E%hGhpBl8B*0NY$&Y|1TPg=z;BCE?;Qn~Hcd)MsF*qPpC0NnX&EFqpqN{8{ z(z9@|)gNc^KNbJ1E$MqA)r{Ra~H(qIZa*gQ~5yxt%Q%Zve{41-W~} z+=EONz2G744ju|vKeDBs4+;Sbv@`LRS5o#PA)($z`j#ff_)v_Sqk@mBx39TPupY+2 zAEFSV;7wKvamN#II`$YnT@`YOxB|=zAEcyY>K9~aXC7c{2AV+2LwywNLLKFi-j4E) z7Ki|h8y-V6v_=s;bR9yJ9gNV{M&KjVS63f}wjwH88>3VqzCP}j0cg01lChr^0Vo+3 zV2M-lP(T5u@bb;b(3eB8Lwku(WGVQYKl#uxMo)oSY{{3F&PH4KmX;v-LJ%^*YcY z*ox$@NA$6fa|iNNtn?wiMp&e;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ksXI^(*bT9Pp2yp%S#^2hETU z*HYAll}j!QMX&^KsF1*g-z1Fx#vH8Rh9p@MOikwN{ZUyhi?q$$JUqT@msreP_~!W^ z^SCDyz=yW(t`8s%6~QLnBS>p0mwp|=sy56i&A2}8>DSgRTeTNZ%VrC%`f3KZd`^C$ z+|kA2=L2#9x2b!LcDek>!_CCc{{Kl>{l>#Vi|HqZmMbC)&Lb}7JKc+-u1}b`xw>AA zIk(0G&)hAn6Pmwqy};?7JeS`mMdY=uQ(MmX!=`tD1K{1M$K&vipolGd3ihdd@CQL? zuV=)o5%x+AQ~utI=+vB{j5!Dy@D6FN>n;3-=h>!mHP5)2OYiLgt*TQCXpAxT#+*vY wwW#A4nSqTbd5A5J2T~4LEVQg`EBL|hJz3&O-##z_{@CZRG_x};gPl10A0|B7DgXcg literal 0 HcmV?d00001 diff --git a/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/README.md b/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/README.md index 0b9064584..284fbc24d 100755 --- a/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/README.md +++ b/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/README.md @@ -1,28 +1,33 @@ # [2257.Count Unguarded Cells in the Grid][title] -> [!WARNING|style:flat] -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) - ## Description +You are given two integers m and n representing a **0-indexed** `m x n` grid. You are also given two 2D integer arrays `guards` and `walls` where `guards[i] = [rowi, coli]` and `walls[j] = [rowj, colj]` represent the positions of the `ith` guard and `jth` wall respectively. + +A guard can see **every** cell in the four cardinal directions (north, east, south, or west) starting from their position unless **obstructed** by a wall or another guard. A cell is **guarded** if there is **at least** one guard that can see it. + +Return the number of unoccupied cells that are **not guarded**. -**Example 1:** +**Example 1:** + +![1](./1.png) ``` -Input: a = "11", b = "1" -Output: "100" +Input: m = 4, n = 6, guards = [[0,0],[1,1],[2,3]], walls = [[0,1],[2,2],[1,4]] +Output: 7 +Explanation: The guarded and unguarded cells are shown in red and green respectively in the above diagram. +There are a total of 7 unguarded cells, so we return 7. ``` -## 题意 -> ... +**Example 2:** -## 题解 +![2](./2.png) -### 思路1 -> ... -Count Unguarded Cells in the Grid -```go ``` - +Input: m = 3, n = 3, guards = [[1,1]], walls = [[0,1],[1,0],[2,1],[1,2]] +Output: 4 +Explanation: The unguarded cells are shown in green in the above diagram. +There are a total of 4 unguarded cells, so we return 4. +``` ## 结语 diff --git a/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/Solution.go b/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/Solution.go index d115ccf5e..bfd5fdbf2 100644 --- a/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/Solution.go +++ b/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/Solution.go @@ -1,5 +1,78 @@ package Solution -func Solution(x bool) bool { - return x +func Solution(m int, n int, guards [][]int, walls [][]int) int { + count := m * n + count -= len(guards) + count -= len(walls) + wm := make(map[int]map[int]struct{}) + for _, w := range walls { + if _, ok := wm[w[0]]; !ok { + wm[w[0]] = make(map[int]struct{}) + } + wm[w[0]][w[1]] = struct{}{} + } + gm := make(map[int]map[int]struct{}) + for _, g := range guards { + if _, ok := gm[g[0]]; !ok { + gm[g[0]] = make(map[int]struct{}) + } + gm[g[0]][g[1]] = struct{}{} + } + + used := make(map[[2]int]struct{}) + for _, g := range guards { + x, y := g[0], g[1] + for i := x - 1; i >= 0; i-- { + if v, ok := gm[i]; ok { + if _, ok := v[y]; ok { + break + } + } + if v, ok := wm[i]; ok { + if _, ok := v[y]; ok { + break + } + } + used[[2]int{i, y}] = struct{}{} + } + + for i := x + 1; i < m; i++ { + if v, ok := gm[i]; ok { + if _, ok := v[y]; ok { + break + } + } + if v, ok := wm[i]; ok { + if _, ok := v[y]; ok { + break + } + } + used[[2]int{i, y}] = struct{}{} + } + + rows := gm[x] + for i := y + 1; i < n; i++ { + if _, ok := rows[i]; ok { + break + } + if v, ok := wm[x]; ok { + if _, ok := v[i]; ok { + break + } + } + used[[2]int{x, i}] = struct{}{} + } + for i := y - 1; i >= 0; i-- { + if _, ok := rows[i]; ok { + break + } + if v, ok := wm[x]; ok { + if _, ok := v[i]; ok { + break + } + } + used[[2]int{x, i}] = struct{}{} + } + } + return count - len(used) } diff --git a/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/Solution_test.go b/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/Solution_test.go index 14ff50eb4..abb129b70 100644 --- a/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/Solution_test.go +++ b/leetcode/2201-2300/2257.Count-Unguarded-Cells-in-the-Grid/Solution_test.go @@ -9,31 +9,31 @@ import ( func TestSolution(t *testing.T) { // 测试用例 cases := []struct { - name string - inputs bool - expect bool + name string + m, n int + guards, walls [][]int + expect int }{ - {"TestCase", true, true}, - {"TestCase", true, true}, - {"TestCase", false, false}, + {"TestCase1", 4, 6, [][]int{{0, 0}, {1, 1}, {2, 3}}, [][]int{{0, 1}, {2, 2}, {1, 4}}, 7}, + {"TestCase2", 3, 3, [][]int{{1, 1}}, [][]int{{0, 1}, {1, 0}, {2, 1}, {1, 2}}, 4}, } // 开始测试 for i, c := range cases { t.Run(c.name+" "+strconv.Itoa(i), func(t *testing.T) { - got := Solution(c.inputs) + got := Solution(c.m, c.n, c.guards, c.walls) if !reflect.DeepEqual(got, c.expect) { - t.Fatalf("expected: %v, but got: %v, with inputs: %v", - c.expect, got, c.inputs) + t.Fatalf("expected: %v, but got: %v, with inputs: %v %v %v %v", + c.expect, got, c.m, c.n, c.guards, c.walls) } }) } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }