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 ...
随机推荐
- 每日一道 LeetCode (9):实现 strStr()
每天 3 分钟,走上算法的逆袭之路. 前文合集 每日一道 LeetCode 前文合集 代码仓库 GitHub: https://github.com/meteor1993/LeetCode Gitee ...
- 微信商户H5支付申请不通过被驳回,拒绝原因提示:网站存在不实内容或不安全信息
一.H5支付简介及使用场景说明 H5支付是指商户在微信客户端外的移动端网页展示商品或服务,用户在前述页面确认使用微信支付时,商户发起本服务呼起微信客户端进行支付.主要用于触屏版的手机浏览器请求微信支付 ...
- 2020重新出发,JAVA入门,关键字&保留字
关键字 & 保留字 关键字(或者保留字)是对编译器有特殊意义的固定单词,不能在程序中做其他目的使用. 关键字具有专门的意义和用途,和自定义的标识符不同,不能当作一般的标识符来使用.例如, cl ...
- JavaScript重定向
使用JavaScript重定向到其他网页的一些方法: location.href location.replace() location.assign() 语法: window.location.hr ...
- TCP/IP速记
目录 网络协议 OSI七层模型和TCP/IP五层模型 TCP/IP五层模型 TCP的三次握手和四次挥手 三次握手进行连接 四次挥手断开连接 TCP连接的特点 TCP是如何保证安全可靠的 UDP连接的特 ...
- 更优雅的配置:docker/运维/业务中的环境变量
目录 docker-compose 环境变量 .env 文件 env_file docker stack 不支持基于文件的环境变量 envsubst envsubst.py 1. 使用行内键值对 2. ...
- WeakHashMap的应用场景
WeakHashMap是啥: WeakHashMap和HashMap都是通过"拉链法"实现的散列表.它们的源码绝大部分内容都一样,这里就只是对它们不同的部分就是说明. WeakR ...
- 性能分析(7)- 未利用系统缓存导致 I/O 缓慢案例
性能分析小案例系列,可以通过下面链接查看哦 https://www.cnblogs.com/poloyy/category/1814570.html 前提 前面有学到 Buffer 和 Cache 的 ...
- ImportError: No module named git
问题:ImportError: No module named git 解决:yum install GitPython
- Java中实现对集合中对象按中文首字母排序
有一个person对象如下: public class Person { private String id;private String nam; } 一个list集合如下: List<Emp ...