Re: [閒聊] 每日leetcode

看板 Marginalman
作者 sixB (6B)
時間 2024-11-21 23:57:08
留言 0 ( 0推 0噓 0→ )
回文 60則
大風起兮 雲飛揚 安得猛士兮 走四方 原本想說八皇后 看一下 m, n <= 10e5 讓阿瓜走四方好像不太好 一隻阿瓜m+n 放滿mn(m+n) 不太對 直接陣列四個方向掃過去惹 class Solution { public: int countUnguarded(int m, int n, vector<vector<int>>& guards, vector<vector<int>>& walls) { //empty: 0, gaurd: 1, wall: 2, see: -1 vector<vector<int>> mat(m, vector<int>(n, 0)); for(auto& g: guards){ mat[g[0]][g[1]] = 1; } for(auto& w: walls){ mat[w[0]][w[1]] = 2; } //m row, n col //see right for(int i = 0; i < m; i++){ int see = 0; for(int j = 0; j < n; j++){ if(mat[i][j] == 0) mat[i][j] = see; else if(mat[i][j] == 1) see = -1; else if(mat[i][j] == 2) see = 0; } } //see left for(int i = 0; i < m; i++){ int see = 0; for(int j = n-1; j >= 0; j--){ if(mat[i][j] == 0) mat[i][j] = see; else if(mat[i][j] == 1) see = -1; else if(mat[i][j] == 2) see = 0; } } //see down for(int j = 0; j < n; j++){ int see = 0; for(int i = 0; i < m; i++){ if(mat[i][j] == 0) mat[i][j] = see; else if(mat[i][j] == 1) see = -1; else if(mat[i][j] == 2) see = 0; } } //see up for(int j = 0; j < n; j++){ int see = 0; for(int i = m-1; i >= 0; i--){ if(mat[i][j] == 0) mat[i][j] = see; else if(mat[i][j] == 1) see = -1; else if(mat[i][j] == 2) see = 0; } } //count int cnt = 0; for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ if(mat[i][j] == 0) cnt++; } } return cnt; } }; 後來發現early return的話 其實把阿瓜放滿 走四方worse case也是4mn m*n 也<= 10e5 想不到什麼厲害解法 如果不能m*n的話甚至不能整個掃一遍 m*n再去扣掉或是bitwise 好像很強== ※ 引述《JIWP (神楽めあ的錢包)》之銘言: : 2257. Count Unguarded Cells in the Grid : 有m*n的二維矩陣 : 在這個二維矩陣上有守衛和牆壁 : 守衛可以看向4個方向(東西南北)直到被牆壁擋住 : 請問這個矩陣上有個cell是不會被守衛看到的? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.121.194 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1732204631.A.D72.html

回文

[閒聊] 每日Leetcode
marginalman Rushia
2022-03-29 10:59:05
[閒聊] 每日LeetCode
1 3 marginalman Rushia
2022-09-14 23:02:29
Re: [閒聊] 每日LeetCode
1 3 marginalman Rushia
2022-09-15 12:15:47
Re: [閒聊] 每日LeetCode
2 2 marginalman pandix
2022-09-15 12:57:55
Re: [閒聊] 每日LeetCode
marginalman Rushia
2022-09-21 15:41:31
Re: [閒聊] 每日LeetCode
3 5 marginalman Rushia
2022-09-21 15:53:41
Re: [閒聊] 每日LeetCode
4 5 marginalman Rushia
2022-09-22 10:40:56
Re: [閒聊] 每日LeetCode
1 6 marginalman yam276
2022-09-22 11:38:13
Re: [閒聊] 每日LeetCode
1 2 marginalman yam276
2022-09-22 16:12:43
Re: [閒聊] 每日LeetCode
2 7 marginalman Rushia
2022-09-24 12:54:51
Re: [閒聊] 每日LeetCode
marginalman Rushia
2022-09-25 15:51:32
Re: [閒聊] 每日LeetCode
2 4 marginalman pandix
2022-09-26 19:55:34
Re: [閒聊] 每日LeetCode
marginalman pandix
2022-09-27 23:40:49
Re: [閒聊] 每日LeetCode
2 5 marginalman Rushia
2022-09-27 23:48:21
Re: [閒聊] 每日LeetCode
2 2 marginalman Rushia
2022-09-28 10:06:53
Re: [閒聊] 每日LeetCode
3 5 marginalman pandix
2022-09-28 19:00:24
Re: [閒聊] 每日LeetCode
4 5 marginalman Rushia
2022-09-29 10:22:39
Re: [閒聊] 每日LeetCode
3 6 marginalman pandix
2022-09-29 10:45:51
Re: [閒聊] 每日LeetCode
marginalman pandix
2022-09-29 23:33:27
Re: [閒聊] 每日LeetCode
3 3 marginalman Rushia
2022-10-01 15:21:10
Re: [閒聊] 每日LeetCode
2 3 marginalman pandix
2022-10-01 23:23:27
Re: [閒聊] 每日LeetCode
3 8 marginalman Pash97143
2022-10-02 00:38:24
Re: [閒聊] 每日LeetCode
2 2 marginalman fxfxxxfxx
2022-10-02 09:00:25
Re: [閒聊] 每日LeetCode
4 5 marginalman pandix
2022-10-02 17:01:46
Re: [閒聊] 每日LeetCode
5 7 marginalman fxfxxxfxx
2022-10-03 09:12:35
Re: [閒聊] 每日LeetCode
4 4 marginalman pandix
2022-10-03 09:37:14
Re: [閒聊] 每日LeetCode
marginalman qwer338859
2022-10-03 11:25:38
Re: [閒聊] 每日LeetCode
5 6 marginalman Rushia
2022-10-03 11:26:31
Re: [閒聊] 每日LeetCode
3 3 marginalman Rushia
2022-10-04 09:52:42
Re: [閒聊] 每日LeetCode
5 5 marginalman Rushia
2022-10-05 09:25:45
Re: [閒聊] 每日LeetCode
4 5 marginalman pandix
2022-10-05 09:40:08
Re: [閒聊] 每日LeetCode
4 6 marginalman Rushia
2022-10-06 10:18:27
Re: [閒聊] 每日LeetCode
marginalman pandix
2022-10-06 10:27:49
Re: [閒聊] 每日LeetCode
1 3 marginalman Rushia
2022-10-06 10:53:34
Re: [閒聊] 每日LeetCode
marginalman fxfxxxfxx
2022-10-06 15:02:54
Re: [閒聊] 每日LeetCode
2 5 marginalman pandix
2022-10-07 12:06:19
Re: [閒聊] 每日LeetCode
1 4 marginalman fxfxxxfxx
2022-10-07 19:36:15
Re: [閒聊] 每日LeetCode
3 3 marginalman Rushia
2022-10-08 12:37:47
Re: [閒聊] 每日LeetCode
marginalman pandix
2022-10-08 13:02:09
Re: [閒聊] 每日LeetCode
2 4 marginalman fxfxxxfxx
2022-10-08 14:13:09
Re: [閒聊] 每日LeetCode
1 1 marginalman SecondRun
2022-10-08 16:09:03
Re: [閒聊] 每日LeetCode
2 2 marginalman Rushia
2022-10-09 14:11:02
Re: [閒聊] 每日LeetCode
1 2 marginalman Rushia
2022-10-10 14:38:07
Re: [閒聊] 每日LeetCode
2 2 marginalman Rushia
2022-10-11 11:21:19
Re: [閒聊] 每日LeetCode
2 3 marginalman Rushia
2022-10-12 10:06:55
Re: [閒聊] 每日LeetCode
6 10 marginalman Rushia
2022-10-13 09:12:42
Re: [閒聊] 每日LeetCode
4 6 marginalman fxfxxxfxx
2022-10-13 12:17:26
Re: [閒聊] 每日LeetCode
6 7 marginalman Rushia
2022-10-14 16:24:57
Re: [閒聊] 每日LeetCode
3 3 marginalman pandix
2022-10-15 18:59:40
Re: [閒聊] 每日LeetCode
4 7 marginalman pandix
2022-10-16 16:24:59
Re: [閒聊] 每日LeetCode
2 2 marginalman Rushia
2022-10-17 09:42:50
Re: [閒聊] 每日LeetCode
2 3 marginalman abcd991276
2022-10-18 15:24:10
Re: [閒聊] 每日LeetCode
1 2 marginalman Rushia
2022-10-18 16:37:56
Re: [閒聊] 每日LeetCode
2 3 marginalman pandix
2022-10-18 16:50:13
Re: [閒聊] 每日LeetCode
marginalman Rushia
2022-10-19 09:45:48
Re: [閒聊] 每日LeetCode
1 3 marginalman pandix
2022-10-19 11:07:59
Re: [閒聊] 每日LeetCode
3 4 marginalman Rushia
2022-10-20 09:21:06
Re: [閒聊] 每日LeetCode
6 6 marginalman fxfxxxfxx
2022-10-21 02:46:22
Re: [閒聊] 每日LeetCode
1 2 marginalman Rushia
2022-10-21 09:12:55
Re: [閒聊] 每日LeetCode
3 4 marginalman pandix
2022-10-22 15:36:18

最新文章

[耍冷] 曹丕岳父喝醉酒
joke eric30526
2024-11-22 01:18:57
[創作] 我們的目的良善
poem icegino
2024-11-21 23:37:10