FZU:http://acm.fzu.edu.cn/problem.php?pid=1920

题意:叫你玩扫雷游戏,已经告诉你地雷的位置了,问你最少点几次鼠标左键可以赢这盘扫雷

题解:直接DFS,(注意这里是8个方向搜索不是4个方向),然后把0周围的不是雷的格子置0,然后统计不是0也不是雷的格子数量,然后加上之前DFS的数量就是答案。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
char mp[][];
int n;
int ans,px[],py[];
int top,s1[],s2[],num;
bool visit[][];
void DFS(int x,int y){//dfs寻找连通0的区域有多少个
int dir[][]={{,},{-,},{,},{,-},{-,-},{-,},{,-},{,}};
for(int i=;i<;i++){
int xx=x+dir[i][];
int yy=y+dir[i][];
if(xx>=&&xx<=n&&yy>=&&yy<=n){
if(mp[xx][yy]==''&&visit[xx][yy]==){
visit[xx][yy]=;
DFS(xx,yy);
}
}
}
}
int main(){
int test;
scanf("%d",&test);
int tt=;
while(test--){
ans=;
scanf("%d",&n);
memset(mp,-,sizeof(mp));
top=;num=;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
cin>>mp[i][j];
if(mp[i][j]==''){
px[++top]=i; py[top]=j;
s1[++num]=i; s2[num]=j;
}
}
}
memset(visit,,sizeof(visit));
while(top>=){
int a=px[top];
int b=py[top--];
if(!visit[a][b]){
visit[a][b]=;
ans++;
DFS(a,b);
}
}
while(num>=){//把0周围的非雷格子至晨0
int a=s1[num];
int b=s2[num--];
if(a>=&&mp[a-][b]!=''&&mp[a-][b]!='@')
mp[a-][b]='';
if(a<n&&mp[a+][b]!=''&&mp[a+][b]!='@')
mp[a+][b]='';
if(b>=&&mp[a][b-]!=''&&mp[a][b-]!='@')
mp[a][b-]='';
if(b<n&&mp[a][b+]!=''&&mp[a][b+]!='@')
mp[a][b+]='';
if(a>=&&b>=&&mp[a-][b-]!=''&&mp[a-][b-]!='@')
mp[a-][b-]='';
if(a>=&&b<n&&mp[a-][b+]!=''&&mp[a-][b+]!='@')
mp[a-][b+]='';
if(a<n&&b>=&&mp[a+][b-]!=''&&mp[a+][b-]!='@')
mp[a+][b-]='';
if(a<n&&b<n&&mp[a+][b+]!=''&&mp[a+][b+]!='@')
mp[a+][b+]='';
}
for(int i=;i<=n;i++){//统计剩余需要点击的格子
for(int j=;j<=n;j++){
if(mp[i][j]!=''&&mp[i][j]!='@')
ans++;
}
}
printf("Case %d: %d\n",tt++,ans);
}
}

Left Mouse Button的更多相关文章

  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 (bfs)

    Mine sweeper is a very popular small game in Windows operating system. The object of the game is to ...

  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. jQuery支持mobile的全屏水平横向翻页效果

    这是一款支持移动手机mobile设备的jQuery全屏水平横向翻页效果插件. 该翻页插件能够使页面在水平方向上左右全屏翻动,它支持手机触摸屏,支持使用鼠标滚动页面. 整个页面过渡平滑,效果很不错. 在 ...

  2. 如何学习一门新技术-iOS开发

    如何快速学习一门新技术 以CoreBluetooth 蓝牙开发为例.我们可以从官方获得的资源有:SampleCode, Documentation,API Reference. 先从Documenta ...

  3. PRD产品需求文档概要

    PRD概念 PRM就是Product Requirements Document的简称,也就是产品需求模型.一般来说一个产品会伴随有市场需求文档(Market Requirements Documen ...

  4. 【bzoj2938】[Poi2000]病毒

    题目描述 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码是安全的.现在委员会已经找出了所有的病毒代码段,试问,是否 ...

  5. HTML特效代码大全

    1)贴图:<img src="图片地址">2)加入连接:<a href="所要连接的相关地址">写上你想写的字</a>1)贴 ...

  6. weex APIs

    1.通过这个$vm()上下文访问这些api在脚本的方法 <script> module.exports = { methods: { somemethod: function() { th ...

  7. .Net framework.

    Figure 1 - .Net Framework The Common Language Runtime (CLR) is the mechanism through which .NET code ...

  8. 玩转CSLA.NET小技巧系列二:使用WCF无法上传附件,提示413 Entity Too Large

    背景:由于系统需要展示图片,客户上传图片到本地客户端目录,然后在数据库中存储本地图片地址,和图片二进制数据 错误原因:我是使用CSLA的WCF服务,使用了数据门户,WCF协议使用的是wsHttpBin ...

  9. 【转】 iOS KVO KVC

    原文: http://www.cocoachina.com/industry/20140224/7866.html Key Value Coding Key Value Coding是cocoa的一个 ...

  10. SGU 150.Mr. Beetle II

    非常烦人的题,思路比较简单,十分容易出错,细节非常重要. 从四个不同的行走方向讨论经过的每一个格子. code: #include <iostream> #include <util ...