Re: [闲聊] 每日leetcode

楼主: sixB (6B)   2024-08-13 01:49:53
a十个零叔叔说刷题没救了
可是我也不知道我还能干嘛QQ
要转什么方向发展比较好啊
真的要学餐饮了吗
703.
今天这题就pq
没想清楚倒过来放就好
想说要random access
所以用vector做二分搜插入
不放扣出来丑人惹:(
1568.
也把昨天那题写完了
突然就顺顺的跑完
缝缝补补分3个case
不过solution好像也差不多
昨天一直没想清楚又一直改
以为每格都扫一次会很慢
constraint其实也才30*30
简单来说就是我太笨
class Solution {
public:
int minDays(vector<vector<int>>& grid) {
int n = grid.size(), m = grid[0].size();
bool flag = false;
vector<vector<int>> check0 = grid;
int land = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
// 1 cut
if(grid[i][j] == 1) {
cut(check0, grid, i, j);
flag = true;
break;
}
}
if(flag) break;
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(check0[i][j] == 1) {
return 0;
}
if(grid[i][j] == 1) land++;
}
}
if(land <= 2) return land;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
// 1 cut
vector<vector<int>> check = grid;
if(grid[i][j] == 1){
grid[i][j] = 0;
check[i][j] = 0;
if(i < n-1 and grid[i+1][j] == 1)
cut(check, grid, i+1, j);
else if(i > 0 and grid[i-1][j] == 1)
cut(check, grid, i-1, j);
else if(j < m-1 and grid[i][j+1] == 1)
cut(check, grid, i, j+1);
else if(j > 0 and grid[i][j-1] == 1)
cut(check, grid, i, j-1);
grid[i][j] = 1;
if((i < n-1 and check[i+1][j]) or\
(i > 0 and check[i-1][j]) or\
(j < m-1 and check[i][j+1]) or\
(j > 0 and check[i][j-1])){
cout << "COOL\n";
cout << i << " " << j << '\n';
return 1;
}
}
}
}
return 2;
}
void cut(vector<vector<int>>& check, vector<vector<int>>& grid, int i, int j){
if(i < 0 or i >= grid.size() or j < 0 or j >= grid[0].size()) return;
if(check[i][j] == 0) return;
check[i][j] = 0;
cut(check, grid, i-1, j);
cut(check, grid, i+1, j);
cut(check, grid, i, j-1);
cut(check, grid, i, j+1);
}
};
楼主: sixB (6B)   2024-08-13 01:51:00
上下左右可以用阵列多写一个循环好像也没少几行
作者: a000000000 (九个零喔)   2024-08-13 02:06:00
尼可以去猪屎屋写firmware还啥的不过填reg这种事跟刷题关C没很大我最近还看过一堆硅谷刷题仔沦落到去猪屎屋作P&R比CAD还惨 CAD好歹算写程式der
作者: ttucse ((((>( ̄▽ ̄)<))))   2024-08-13 02:31:00
CAD是啥,写verilog那种的吗?
作者: a000000000 (九个零喔)   2024-08-13 02:48:00
就在猪屎屋管各种tool的 像cadence synopsys卖得tool
作者: ttucse ((((>( ̄▽ ̄)<))))   2024-08-13 02:54:00
噢噢,所以可能是写shell script或python吗?
作者: a000000000 (九个零喔)   2024-08-13 02:54:00
都有R
作者: ttucse ((((>( ̄▽ ̄)<))))   2024-08-13 02:55:00
了了,感谢。
作者: devilkool (对猫毛过敏的猫控)   2024-08-13 02:58:00
刷题仔会p&r喔@@
作者: a000000000 (九个零喔)   2024-08-13 03:05:00
尼挂EE学位摸点vlsi也很正常八
楼主: sixB (6B)   2024-08-13 05:13:00
好像真的只能写韧体惹 嵌入式还有机会ㄇ

Links booklink

Contact Us: admin [ a t ] ucptt.com