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);
}
};