FZU 1920 Left Mouse Button 简单搜索

题意就是扫雷 问最少多少次可以把图点开……

思路也很明显 就是先把所有的标记一遍 就当所有的都要点……

录入图……

所有雷都不标记……

之后呢 遍历图……

然后碰到0就搜索一圈 碰到数字就标记……

不难 但是卡了好久……

直接上代码……

#include<stdio.h>
#include<string.h>

char s[12][12];
bool vis[12][12];
int n;
int dx[10]={0,0,1,-1,1,-1,1,-1};
int dy[10]={1,-1,0,0,-1,1,1,-1};

void dfs(int x,int y){
    if(!vis[x][y]) return ;
    if(x<1&&x>n&&y<1&&y>n) return ;
    vis[x][y]=false;
    if(s[x][y]!=‘0‘) return ;
    else{
        for(int i=0;i<8;i++)
            dfs(x+dx[i],y+dy[i]);
    }
}

int main(){
    int T;
    scanf("%d",&T);
    int time=1;
    while(T--){
        scanf("%d",&n);
        memset(vis,true,sizeof(vis));
        char ss[12];
        for(int i=1;i<=n;i++){
            scanf("%s",ss);
            for(int j=0;j<n;j++){
                s[i][j+1]=ss[j];
                if(s[i][j+1]==‘@‘) vis[i][j+1]=false;
            }
        }
        /*puts("");
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                printf("%c",s[i][j]);
            }
            puts("");
        }
        puts("");*/
        int sum=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(s[i][j]==‘0‘&&vis[i][j]){
                    sum++;
                    dfs(i,j);
                }
            }
        }
        /*for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                printf("%c",vis[i][j]?‘1‘:‘0‘);
            }
            puts("");
        }*/
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                if(vis[i][j]) sum++;
        printf("Case %d: %d\n",time++,sum);
    }
    return 0;
}
时间: 2024-08-03 18:53:58

FZU 1920 Left Mouse Button 简单搜索的相关文章

fzu 1920 Left Mouse Button(简单深搜题)

题目地址:http://acm.fzu.edu.cn/problem.php?pid=1920 题目大意是给定一个n*n的图,模拟扫雷游戏,0代表没有雷区,1代表附近九宫格内只有一个雷-- 如果不懂的话去玩下扫雷,挺好玩的,99个雷的玩了好几百盘才赢了一次............ 此题假设神操作,点不到雷,问你最少要多少下才可以把图中非雷的点完,怎么样才最快呢? 当然先点0啦,,,,,,,, 好吧,不废话了..... ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1

FZU - 1920 Left Mouse Button

FZU - 1920 Left Mouse Button Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Description Mine sweeper is a very popular small game in Windows operating system. The object of the game is to find mines, and mar

专题一、简单搜索 - Virtual Judge

很久以前刷完了Virtual Judge上的简单搜索专题,现总结如下: POJ 1321 由于题目的数据范围比较小,可以直接dfs暴力.读入时记录每个空位的位置,保存在pX[]以及pY[]数组中.暴力的时候统计当前处理第几个空格以及当前处理到了第几行即可. #include <iostream> #include <memory.h> using namespace std; const int MAX = 128; long long ans; int N, K, nCnt; b

kuangbin带你飞专题一 简单搜索 题解

目录 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题一 简单搜索 总结:用时2天半终于把这个专题刷完了 对于最基础的dfs bfs 路径打印 状态转移也有了一点自己些微的理解 其实2天半可以压缩到1天半的 主要是自己太懒了...慢慢加油刷bin神的专题呀 从大二下学期开始学算法 一开始就知道这个专题 一开始对于这个专题里的所有问题感觉都好难啊..就直接放弃了 看lrj的书 现在看到这个专题还挺唏嘘的吧 突然觉得思维和想法也不是很难 果然是那个时候心不静&还是储量不够吗

FZU 1920

Description Mine sweeper is a very popular small game in Windows operating system. The object of the game is to find mines, and mark them out. You mark them by clicking your right mouse button. Then you will place a little flag where you think the mi

FZU 2150 Fire Game --两点同步搜索

枚举两点,然后同步BFS,看代码吧,很容易懂的. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <queue> #define Mod 1000000007 using namespace std; struct Po

java 模拟简单搜索

Java 模拟简单搜索 实体类 package org.dennisit.entity; /** * * * @version : 1.0 * * @author : 苏若年 <a href="mailto:[email protected]">发送邮件</a> * * @since : 1.0 创建时间: 2013-4-8 下午04:51:03 * * @function: TODO * */ public class Medicine { private I

lucene4.3简单搜索示例代码

原文:lucene4.3简单搜索示例代码 源代码下载地址:http://www.zuidaima.com/share/1550463715560448.htm   示例代码,请牛哥们多

参与过三次搜索引擎发展转折的百度,为什么要回归“简单搜索”

相信在搜索引擎技术产品化的二十余年间,我们早已经习惯了搜索引擎的商业化.不过在最近的数博会上,李彦宏却展示了一款名为"简单搜索"的语音交互搜索App,并且声明简单搜索永无广告. 相信很多人也曾想象过这样一款产品--通过语音发问,得出最简单的答案.不过可能大多数人没有想到,推出这款产品的是百度.很长一段时间内,百度的搜索引擎商业化一直为人诟病.但这次百度率先推出永无广告的语音交互搜索,无疑是在搜索引擎的技术和产品形式上都进行了重要创新. 当我们在质疑大企业的创新能力时常常会忽视一点,在技