打开这个题,做了一半躺下了。

结果,怎么都睡不着。一会一个想法,忍不住爬起来提交,要么错误,要么超时。

按照常规思路,依次对每个点检测是否是闭包,再替换,超时。计算量太大了。

还能怎么做呢?没思路,关机睡觉!

躺着睡不着了,思考吧。。。闭着眼睛运行代码。。

突然灵机一动,可以反着来啊!

先把非法的干掉,剩下的就是合法的,不再检测,直接替换就可以了。

而且用到了我平时编辑Word常用的方式,先用一个mark来保护不应该替换的!

哈哈  巧妙!

按耐不住,再次爬起来,1分钟敲完代码,提交,AC!激动!

大半夜的做题,我也是疯魔了。。老天看在我这么努力的份上。。让我赶紧开窍吧!

为啥是B,因为代表bad blocks~~

void fill_with_b(char **board, int i, int j, int m, int n)
{
if(i < || i > m- || j < || j > n-) return;
if(board[i][j] == 'O')
{
board[i][j] = 'B';
fill_with_b(board,i+,j,m,n);
fill_with_b(board,i-,j,m,n);
fill_with_b(board,i,j-,m,n);
fill_with_b(board,i,j+,m,n);
}
}
void replace_b(char **board, int m, int n)
{
int i, j;
for(i = ; i < m; i++)
{
for(j = ; j < n; j++)
{
if(board[i][j] == 'B')
{
board[i][j] = 'O';
}
}
}
}
void solve(char** board, int m, int n) { if(board == NULL || m*n ==) return;
if(m < || n < ) return; int i,j; for(i = ; i < m; i++)
{
if(board[i][] == 'O')
fill_with_b(board,i,,m,n);
if(board[i][n-] == 'O')
fill_with_b(board,i,n-,m,n);
} for(j = ; j < n ; j++)
{
if(board[][j] == 'O')
fill_with_b(board,,j,m,n);
if(board[m-][j] == 'O')
fill_with_b(board,m-,j,m,n);
} for(i=;i<m;i++)
{
for(j=;j<n;j++)
{
if(board[i][j] == 'O')
board[i][j] = 'X';
}
}
replace_b(board,m,n); }

130. Surrounded Regions 卧槽!我半梦半醒之间做出来的。的更多相关文章

  1. leetcode 200. Number of Islands 、694 Number of Distinct Islands 、695. Max Area of Island 、130. Surrounded Regions

    两种方式处理已经访问过的节点:一种是用visited存储已经访问过的1:另一种是通过改变原始数值的值,比如将1改成-1,这样小于等于0的都会停止. Number of Islands 用了第一种方式, ...

  2. 130. Surrounded Regions(M)

    130.Add to List 130. Surrounded Regions Given a 2D board containing 'X' and 'O' (the letter O), capt ...

  3. [LeetCode] 130. Surrounded Regions 包围区域

    Given a 2D board containing 'X' and 'O'(the letter O), capture all regions surrounded by 'X'. A regi ...

  4. 【LeetCode】130. Surrounded Regions (2 solutions)

    Surrounded Regions Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A ...

  5. 130. Surrounded Regions

    题目: Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is capt ...

  6. 【一天一道LeetCode】#130. Surrounded Regions

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  7. 130. Surrounded Regions(周围区域问题 广度优先)(代码未完成!!)

    Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'. A reg ...

  8. Leetcode 130. Surrounded Regions

    Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'. A reg ...

  9. 130. Surrounded Regions -- 被某字符包围的区域

    Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...

随机推荐

  1. [转][html]设置IIS 默认页

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.we ...

  2. C++根据传入的函数指针来解析需要的参数

    C++可以根据传入的函数指针,获取自己需要的参数类型,然后根据参数源中获取需要的参数,这里我用tuple作为演示,不过,只要可以根据序号,或者顺序方式等获取实参,都可以使用类似的方式实现: 先给出一个 ...

  3. idea关闭标签快捷键修改----兼 常用实用快捷键

    还有一个快捷键: 自动补全返回值 : ctrl + alt + v alt + enter: 自动添加未定义的方法 idea 原本的关闭快捷键是: ctrl + F4,但是不好用,谁的手指伸这么长 修 ...

  4. Composer 安装时要求输入授权用户名密码

    composer require "overtrue/laravel-socialite:~2.0" Authentication required (packagist.phpc ...

  5. 超实用!9个目前流行的MATERIAL DESIGN前端框架

    http://www.uisdc.com/material-design-frameworks-top-9 谷歌推出的Material Design风格已见有一些APP UI采用,视觉和交互体验都很棒 ...

  6. Gini系数的原理

    转载:https://blog.csdn.net/u010665216/article/details/78528261 首先,我们直接构造赛题结果:真实数据与预测数据: predictions = ...

  7. php namespace use 研究

    1.file1.php: <?php namespace foos; class demo{ function testfn(){ echo "sdlkfjskdjf"; } ...

  8. 08 bash特性--shell脚本编程入门

    shell脚本编程入门 编程语言介绍 编程语言分为:机械语言.汇编语言和高级语言: 计算机能识别的语言为机械语言,而人类能学习的并且能够方便掌握的为高级语言,所以,我们所编写的程序就要通过编译来转换成 ...

  9. es6(15)--generator

    //generator处理异步,下一步用next,遇到return或者yied就会停止 { //generator基本定义 let tell=function* (){ yield 'a'; yiel ...

  10. es6(13)--Promise

    //Promise { //原始方法 let ajax=function(callback){ console.log('执行') setTimeout(function(){ callback&am ...