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

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

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

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

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

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

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

而且用到了我平时编辑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. flume-sink

    概述 从Flume Agent移除数据并写入到另一个Agent或数据存储或一些其他存储系统的组件被称为sink.Sink不断的轮询channel中的事件且批量的移除它们.这些事件批量写入到存储或索引系 ...

  2. docker拉取oracle11g镜像配置

    开始拉取oracle11g镜像 下载过程稍长,镜像大小6.8G(之前拉取过了,所以就不截图了) #docker pull registry.cn-hangzhou.aliyuncs.com/helow ...

  3. [UE4]蓝图比C++慢10倍,是吗?

    首先,蓝图肯定是比C++慢. 任何脚本语言(需要解释执行的语言),和C++相比可能达到十倍甚至百倍的差距.比如Java.Python.Lua,JS. 脚本语言是运行在虚拟机上的,所以它们比起直接运行的 ...

  4. SCCM 2012 R2实战系列之八:OSD(上)--分发全新Windows7系统

    今天将跟大家一起分享SCCM 中最为重要的一个功能---操作系统分发(OSD),在此文章中会讨论到OSD的初始化配置.镜像的导入.任务序列的创建编辑.并解决大家经常遇到的分发windows7系统分区盘 ...

  5. Mybatis 系列7-结合源码解析核心CRUD 配置及用法

    [Mybatis 系列10-结合源码解析mybatis 执行流程] [Mybatis 系列9-强大的动态sql 语句] [Mybatis 系列8-结合源码解析select.resultMap的用法] ...

  6. C#存储过程 传入参数 传出参数 结果集

    作者:卞功鑫 转载请保留:http://www.cnblogs.com/BinBinGo/p/6400928.html //1 连接字符串 string connectionString = &quo ...

  7. 用singleton单例模式实现一个模块

    对于具有唯一性的模块(例如,购物车项目中的物品数据,各个页面都要使用它,而且是唯一的数据),用singleton模式. var mySingleton = (function() { var priv ...

  8. Ren'Py视觉小说安装,玩一下吧,上班很闲的话

    ---------------------------------------------------------------------------------------------------- ...

  9. jieba gensim 用法

    简单的问答已经实现了,那么问题也跟着出现了,我不能确定问题一定是"你叫什么名字",也有可能是"你是谁","你叫啥"之类的,这就引出了人工智能 ...

  10. 数据库数据以Excel的方式导出

    import java.io.Serializable; import java.util.List; import com.cfets.cwap.s.util.db.TableColumn; /** ...