Left Mouse Button (bfs)
Input
Output
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)的更多相关文章
- FZU1920 Left Mouse Button(dfs)
Problem 1920 Left Mouse Button Accept: 385 Submit: 719 Time Limit: 1000 mSec Memory Limit : 3 ...
- Left Mouse Button
FZU:http://acm.fzu.edu.cn/problem.php?pid=1920 题意:叫你玩扫雷游戏,已经告诉你地雷的位置了,问你最少点几次鼠标左键可以赢这盘扫雷 题解:直接DFS,(注 ...
- FZU 1920 Left Mouse Button 简单搜索
题意就是扫雷 问最少多少次可以把图点开…… 思路也很明显 就是先把所有的标记一遍 就当所有的都要点…… 录入图…… 所有雷都不标记…… 之后呢 遍历图…… 然后碰到0就搜索一圈 碰到数字就标记…… 不 ...
- wx.button
wx.Button A button is a control that contains a text string, and is one of the most common elements ...
- jQuery中有关mouse的事件--mousedown/up/enter/leave/over/out----2017-05-10
mousedown:鼠标按下才发生 mouseup:鼠标按下松开时才发生 mouseenter和mouseleave效果和mouseover mouseout效果差不多:但存在区别,区别见代码解析: ...
- Javascript Madness: Mouse Events
http://unixpapa.com/js/mouse.html Javascript Madness: Mouse Events Jan WolterAug 12, 2011 Note: I ha ...
- js & listen mouse click
js & listen mouse click how to listen mouse click in js https://www.kirupa.com/html5/mouse_event ...
- Drag & drop a button widget
In the following example, we will demonstrate how to drag & drop a button widget. #!/usr/bin/pyt ...
- [转]dojo/mouse
dojo/mouse Authors:Kris Zyp Project owner:Kris Zyp since:1.7.0 Contents Usage enter leave mouseButto ...
随机推荐
- requests入门实践02_下载斗图拉最新表情包
新版本移步:https://www.cnblogs.com/zy7y/p/13376228.html 下载斗图拉最新表情包 要爬取的目标所在网址:http://www.doutula.com/phot ...
- 8月份Python招聘情况怎么样?Python爬取招聘数据,并进行分析
前言 拉勾招聘是专业的互联网求职招聘平台.致力于提供真实可靠的互联网招聘求职找工作信息.今天我们一起使用 python 采集拉钩的 python 招聘信息,分析一下找到高薪工作需要掌握哪些技术 开发环 ...
- Android 菜单的使用
有时间就随笔记录自己遇到的问题和所学的知识哈. 这是对本牛崽知识的提升也可以给其他牛牛们来点鸡汤和开胃菜. 菜单Menu的创建 首先menu是属于布局的嘛,所以嘞,咱们得在res(也就是布局资源)创建 ...
- python4.3内置函数
常见的内置函数 a=[12,31,31,232,34,32,43,54,36]max1=max(a)#最大函数print(max1)min1=min(a)#最小函数print(min1)sum1=su ...
- udevd启动失败问题
最近用到udev自动挂载U盘,下载udev源码编译后,放在设备里运行,发现udev启动后立即就退出了, 通过加--debug参数可以看到输出错误信息: [root@DMF:dev]#mkdir .ud ...
- 一张图理清 Python3 所有知识点
如果你前几天一直有关注 GitHub Trending,那你应该会留意到「Python3 in one pic」这个开源项目. 很多人学习python,不知道从何学起.很多人学习python,掌握了基 ...
- 朴素贝叶斯分类器基本代码 && n折交叉优化 2
这个代码基于上一个代码 不同的是:读取了txt文件,改变了min_ft与max_ft的参数 import re import pandas as pd import warnings import n ...
- Java流程控制,for,switch,while.break,continue,return
Java流程控制,for,switch,while.break,continue,return
- GitLab Admin Area 500 Error
GitLab Admin Area 500 Error GitLab Admin Area Settings 菜单全部报错 500 解决方法 执行: gitlab-rake cache:clear # ...
- java_数据类型转换、运算符
数据类型转换 Java程序中要求参与计算的数据,必须要保证数据类型一致,如果数据类型不一致将发生类型的转换. 1.1 自动转换 一个 int 类型变量和一个 byte 类型变量进行加法运算,运算结果, ...