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 ...
随机推荐
- jQuery 发布微博案例
.box { width: 500px; height: 500px; border: 1px solid #efefef; margin: 0 auto; text-align: center; } ...
- ConHost.exe机制
- C++socket编程write()、read()简介及与send()、recv()的区别
1. write 函数原型:ssize_t write(int fd, const void*buf,size_t nbytes)write函数将buf中的nbytes字节内容写入文件描述符fd.成功 ...
- C#LeetCode刷题之#231-2的幂(Power of Two)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3858 访问. 给定一个整数,编写一个函数来判断它是否是 2 的幂 ...
- Android 开发学习进程0.16 layout_weight属性 R文件关联XML Module
layout_weight属性 layout_weight属性我们常常用到,但有时候会发现它还有一些奇怪的属性,比如大多数使用时会把宽度设置成0,但要是宽度不设置成0会有什么效果? layout_we ...
- Nginx CORS 跨域资源共享问题
## 背景 新项目上线,前后端分离,遇到了跨域资源共享的问题,导致请求根本无法发送到后端,前端和后端貌似只能有一个来处理跨域问题,我们这边要采用nginx来解决跨域问题. ## Nginx的CORS配 ...
- SSM整合 完美支持RESTful(Jsp和客户端<android ios...>)
一 RESTful简介 RESTful是一种网络应用程序的设计风格和开发方式 它结构清晰 符合标准 易于理解 扩展方便 REST 即Representational State Transfer的缩写 ...
- Virtuoso 中如何优化 Library Manager 的显示
https://www.cnblogs.com/yeungchie/ 主要从 cds.lib 文件去入手. 假设现在想把 Virtuoso 预装的库整理到 preload 分类(库)中. 首先创建一个 ...
- unity探索者之iOS微信登录、分享
版权声明:本文为原创文章,转载请声明http://www.cnblogs.com/unityExplorer/p/8405700.html iOS接入微信的SDK相对于安卓要麻烦一点,除了核心功能代码 ...
- echarts 导出为word文档
https://www.jianshu.com/p/5bd47ab59bbe 主要思路:前台echarts生成图片后,获取base64码,传给后台解析,然后写入freemarker模板,进行下载. 图 ...