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 ...
随机推荐
- PHP7 生产环境队列 Beanstalkd 正确使用姿势
应用场景 为什么要用呢,有什么好处?这应该放在最开头说,一件东西你只有了解它是干什么的,适合干什么,才能更好的与自己的项目相结合,用到哪里学到哪里,学了不用等于不会,我们平时就应该多考虑一些这样的问题 ...
- Web 开发必须掌握的三个技术:Token、Cookie、Session
在Web应用中,HTTP请求是无状态的.即:用户第一次发起请求,与服务器建立连接并登录成功后,为了避免每次打开一个页面都需要登录一下,就出现了cookie,Session. Cookie Cookie ...
- 导航菜单(动画)--- jQuery
本文章实现是一个导航菜单的功能 (1)点击当前菜单显示二级菜单,再次点击收起当前菜单. (2)当有一个二级菜单显示,点击其他菜单,上一个已点击菜单会收起.只展示当前点击的菜单,只显示一个菜单,类似手风 ...
- JS学习第六天
匿名函数: 定义:function(参数列表){ 要执行的语句块: } 定义名(): 创建日期对象:Date var date=new Date(); alert(date); 不输入则是默认月,日 ...
- tableauRFM分析
1.数据源 2.创建相关字段 2.1 购买点会员生命期 2.2 会员最后购买时间 2.3 最后购买点生命期 3.近一个月老客户的生命期情况 排除了当天创建当天购买的情况,可以看到超市的大部分用户是两年 ...
- C#LeetCode刷题-排序
排序篇 # 题名 刷题 通过率 难度 56 合并区间 31.2% 中等 57 插入区间 30.4% 困难 75 颜色分类 48.6% 中等 147 对链表进行插入排序 50.7% 中等 ...
- 封装react antd的form表单组件
form表单在我们日常的开发过程中被使用到的概率还是很大的,比如包含了登录.注册.修改个人信息.新增修改业务数据等的公司内部管理系统.而在使用时这些表单的样式如高度.上下边距.边框.圆角.阴影.高亮等 ...
- vue cli3.0使用svg全过程
VUE-cli3使用 svg-sprite-loader svg-sprite-loader 的插件,用来根据导入的 svg 文件自动生成 symbol 标签并插入 html 1.安装依赖 npm i ...
- 【SCOI2013】摩托车交易 - 最大生成树+树链剖分
题目描述 mzry1992 在打完吊针出院之后,买了辆新摩托车,开始了在周边城市的黄金运送生意.在mzry1992 生活的地方,城市之间是用双向高速公路连接的.另外,每条高速公路有一个载重上限,即在不 ...
- add application window with unknown token XXX Unable to add window;is your activity is running?
报错: Attempted to add application window with unknown token XXX Unable to add window——token android.o ...