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

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

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

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

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

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

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

而且用到了我平时编辑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. Springboot监控之一:SpringBoot四大神器之Actuator之2--覆盖修改spring cloud的默认的consul健康检查规则

    微服务网关是socket长连接与支付公司对接,该网关需要提供http接口给内部系统调用,当socket没有建立连接时(网关服务的高可用是haProxy搭建的,有些服务的socket可能未连上支付公司) ...

  2. slice和splice

    slice //截取数组或者字符串,返回数组或字符串 //jquery方法截取元素,构成新的对象 splice //增加,修改,删除数组

  3. 廖雪峰Java4反射与泛型-1反射-1Class类

    1.Class类与反射定义 Class类本身是一种数据类型(Type),class/interface的数据类型是Class,JVM为每个加载的class创建了唯一的Class实例. Class实例包 ...

  4. (转)Makefile介绍

    2. Makefile介绍 make命令执行时,需要一个Makefile文件,以告诉make命令需要怎么样的去编译和链接程序. 首先,我们用一个示例来说明Makefile的书写规则.以便给大家一个感性 ...

  5. 09 shell脚本程序练习

    练习1:写一个脚本程序,完成以下任务 1.添加五个用户,user1.user2.user3.user4.user5: 2.添加之前先判断是否存在该用户,如果存在则显示“某某用户已存在”: 3.每个用户 ...

  6. 6.6安装编译安装zabbix3.2

    添加yum源 get -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo #安装阿里云y ...

  7. vue打印html

    # vue打印功能 console.log(data.doPrint); // html字符串 let newContent =data.doPrint; let oldContent = docum ...

  8. useful tools and website

    1.https://www.processon.com/   在线流程图制作网站 2.http://www.easyicon.net/  专门下载图标的网站 3.https://www.lfd.uci ...

  9. mysql 存储过程动态拼接sql并执行赋值

    )) BEGIN ## 定义变量 ,) ; ## @表示全局变量 相当于php $ ## 拼接赋值 INTO 必须要用全局变量不然语句会报错 SET @strsql = CONCAT('SELECT ...

  10. 零基础学习python_with(34课)

    今天学习的with语句,with的表达形式如下:据说context必须是上下文管理器,这我就懵比了,啥玩意啊... with语句的表达形式: with context as var:    block ...