Mine sweeper is a very popular small game in Windows operating system. The object of the game is to find mines, and mark them out. You mark them by clicking your right mouse button. Then you will place a little flag where you think the mine is. You click your left mouse button to claim a square as not being a mine. If this square is really a mine, it explodes, and you lose. Otherwise, there are two cases. In the first case, a little colored numbers, ranging from 1 to 8, will display on the corresponding square. The number tells you how many mines are adjacent to the square. For example, if you left-clicked a square, and a little 8 appeared, then you would know that this square is surrounded by 8 mines, all 8 of its adjacent squares are mines. In the second case, when you left-click a square whose all adjacent squares are not mines, then all its adjacent squares (8 of its adjacent squares) are mine-free. If some of these adjacent squares also come to the second case, then such deduce can go on. In fact, the computer will help you to finish such deduce process and left-click all mine-free squares in the process. The object of the game is to uncover all of the non-mine squares, without exploding any actual mines. Tom is very interesting in this game. Unfortunately his right mouse button is broken, so he could only use his left mouse button. In order to avoid damage his mouse, he would like to use the minimum number of left clicks to finish mine sweeper. Given the current situation of the mine sweeper, your task is to calculate the minimum number of left clicks.

Input

The first line of the input contains an integer T (T <= 12), indicating the number of cases. Each case begins with a line containing an integer n (5 <= n <= 9), the size of the mine sweeper is n×n. Each of the following n lines contains n characters M ij(1 <= i,j <= n), M ij denotes the status of the square in row i and column j, where ‘@’ denotes mine, ‘0-8’ denotes the number of mines adjacent to the square, specially ‘0’ denotes there are no mines adjacent to the square. We guarantee that the situation of the mine sweeper is valid.

Output

For each test case, print a line containing the test case number (beginning with 1) and the minimum left mouse button clicks to finish the game.

Sample Input

1
9
001@11@10
001111110
001111110
001@22@10
0012@2110
221222011
@@11@112@
2211111@2
000000111

Sample Output

Case 1: 24

思路:把和以零为开始点的周围8个位置为数字,且不为0标记,然后扩展
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e5+;
typedef long long ll;
using namespace std;
char Map[][];
int vis[][];
struct node
{
int x,y;
}; int dir[][]={{,},{,-},{,},{-,},{-,-},{,-},{,},{-,}};
void bfs(int x,int y)
{
node start;
start.x=x;
start.y=y;
queue<node>q;
vis[x][y]=;
q.push(start);
while(!q.empty())
{ node now;
now=q.front();
for(int t=;t<;t++)
{
int xx,yy;
xx=now.x+dir[t][];
yy=now.y+dir[t][];
if(Map[xx][yy]>=''&&Map[xx][yy]<='')
{
vis[xx][yy]=;
}
}
//cout<<now.x<<" "<<now.y<<endl;
q.pop();
for(int t=;t<;t++)
{
node next;
next.x=now.x+dir[t][];
next.y=now.y+dir[t][];
if(Map[next.x][next.y]==''&&vis[next.x][next.y]==)
{
vis[next.x][next.y]=;
q.push(next); }
}
} }
int main()
{
int T;
cin>>T;
int n;
int cnt=;
while(T--)
{
int s=;
scanf("%d",&n);
memset(vis,,sizeof(vis));
for(int t=;t<n;t++)
{
scanf("%s",Map[t]);
}
for(int t=;t<n;t++)
{
for(int j=;j<n;j++)
{
if(Map[t][j]==''&&vis[t][j]==)
{
bfs(t,j);
s++;
}
}
}
for(int t=;t<n;t++)
{
for(int j=;j<n;j++)
if(Map[t][j]>=''&&Map[t][j]<=''&&vis[t][j]==)
{
//cout<<t<<" "<<j<<endl;
s++;
}
}
printf("Case %d: %d\n",cnt++,s);
} return ;
}
												

Left Mouse Button (bfs)的更多相关文章

  1. FZU1920 Left Mouse Button(dfs)

     Problem 1920 Left Mouse Button Accept: 385    Submit: 719 Time Limit: 1000 mSec    Memory Limit : 3 ...

  2. Left Mouse Button

    FZU:http://acm.fzu.edu.cn/problem.php?pid=1920 题意:叫你玩扫雷游戏,已经告诉你地雷的位置了,问你最少点几次鼠标左键可以赢这盘扫雷 题解:直接DFS,(注 ...

  3. FZU 1920 Left Mouse Button 简单搜索

    题意就是扫雷 问最少多少次可以把图点开…… 思路也很明显 就是先把所有的标记一遍 就当所有的都要点…… 录入图…… 所有雷都不标记…… 之后呢 遍历图…… 然后碰到0就搜索一圈 碰到数字就标记…… 不 ...

  4. wx.button

    wx.Button A button is a control that contains a text string, and is one of the most common elements ...

  5. jQuery中有关mouse的事件--mousedown/up/enter/leave/over/out----2017-05-10

    mousedown:鼠标按下才发生 mouseup:鼠标按下松开时才发生 mouseenter和mouseleave效果和mouseover mouseout效果差不多:但存在区别,区别见代码解析: ...

  6. Javascript Madness: Mouse Events

    http://unixpapa.com/js/mouse.html Javascript Madness: Mouse Events Jan WolterAug 12, 2011 Note: I ha ...

  7. js & listen mouse click

    js & listen mouse click how to listen mouse click in js https://www.kirupa.com/html5/mouse_event ...

  8. Drag & drop a button widget

    In the following example, we will demonstrate how to drag & drop a button widget. #!/usr/bin/pyt ...

  9. [转]dojo/mouse

    dojo/mouse Authors:Kris Zyp Project owner:Kris Zyp since:1.7.0 Contents Usage enter leave mouseButto ...

随机推荐

  1. 将map中的json转ObjecId

    我们直接从gridfs中取文件列表时取出来的文件_id为: "_id": { "timestamp": 1587091947, "counter&qu ...

  2. Android RecyclerView的补充。

    明天写吧.. 今天写,然后再写今天的内容,虽然结课了,我们还是得学习,所以如果我学习了一些知识,不出意外每天会持续更新的. RecyclerView其实是可以完全代替ListView的存在, 但是为啥 ...

  3. Android 布局的一些控件的补充和布局的补充(今儿没课)

    前面写的博客可能会有点乱: 1,是不太会排版. 2,就是我一边看书,一边听学长讲课,所以有的知识就融入进去了,我写的都是自己的意见和理解,大家取我精华,弃我糟粕哈. 今天是书上的内容,主要讲布局的,一 ...

  4. easyPOI使用

    更多的easyPOI资源的网在easypoi的官网. 1 在pom.xml中添加依赖 <dependency> <groupId>cn.afterturn</groupI ...

  5. 浅析Facebook LibraBFT与比原链Bystack BBFT共识

    如果说什么是区块链的灵魂,那一定是共识机制. 它是区块链的根基.无论公链或是联盟链,共识机制都从基础上限制了区块链的交易处理能力和扩展性. 2019年6月18日,Facebook 发布了自己 Libr ...

  6. java循环语句while与do-while

    一 while循环 while循环语句和选择结构if语句有些相似,都是根据条件判断来决定是否执行大括号内的执行语句. 区别在于,while语句会反复地进行条件判断,只要条件成立,{}内的执行语句就会执 ...

  7. Butterfly侧边栏引入一言

    此教程涉及修改源码 背景 在修改每页显示7篇文章后,出现了这种情况. 这是完美主义(强迫症)的我所不能忍受的,有什么可以占据这里的呢?{% btn 'https://hitokoto.cn/',一言, ...

  8. python2.7用socks和socket设置代理

    接下来是最近遇到的一个代理问题. 背景:一个基于python2.7的自动化测试项目 目的:因调试需求,需要通过代理连接其他公司的前端网站,来检验项目运行所在的问题. 问题:RUN>等了1分钟没有 ...

  9. adb修改手机分辨率

    一.手机分辨率对照表 宽×高(标准值) 240×320 320×480 480×800 720×1280 1080×1920 1440×2560 DPI等级 LDPI MDPI HDPI XHDPI ...

  10. 简单的股票信息查询系统 1 程序启动后,给用户提供查询接口,允许用户重复查股票行情信息(用到循环) 2 允许用户通过模糊查询股票名,比如输入“啤酒”, 就把所有股票名称中包含“啤酒”的信息打印出来 3 允许按股票价格、涨跌幅、换手率这几列来筛选信息, 比如输入“价格>50”则把价格大于50的股票都打印,输入“市盈率<50“,则把市盈率小于50的股票都打印,不用判断等于。

    '''需求:1 程序启动后,给用户提供查询接口,允许用户重复查股票行情信息(用到循环)2 允许用户通过模糊查询股票名,比如输入“啤酒”, 就把所有股票名称中包含“啤酒”的信息打印出来3 允许按股票价格 ...