zoukankan      html  css  js  c++  java
  • 1970:【15NOIP普及组】扫雷游戏

    摘要:http://ybt.ssoier.cn:8088/problem_show.php?pid=1970

    今日复习:DFS

    复习题目:(真题)1970:【15NOIP普及组】扫雷游戏

    上代码!!!!

    #include<bits/stdc++.h>
    using namespace std;
    int f[8][2]={{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};//方向
    int n,m;
    char mp[105][105];//地图 
    int b[105][105]={0};//答案(计数) 
    //测试 
    void pr(){
        cout<<"------------"<<endl;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(mp[i][j]=='*')
                    cout<<mp[i][j];
                else cout<<b[i][j];
            }
            cout<<endl;
        }
    }
    void dfs(int x,int y){
        int nx,ny;
        for(int i=0;i<8;i++){
    //        pr();
            nx=x+f[i][0];
            ny=y+f[i][1];
            
            if(nx>=0 && nx<n && ny>=0 && ny<m){
                b[nx][ny]++;
            }
        }
    } 
    int main(){
        cin>>n>>m;
        for(int i=0;i<n;i++) cin>>mp[i];
    //    pr();
        //遍历 
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(mp[i][j]=='*'){
                    dfs(i,j);
                }
            } 
        } 
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(mp[i][j]=='*')
                    cout<<mp[i][j];
                else cout<<b[i][j];
            }
            cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Node.js Net 模块+DNS 模块
    php程序报500错误
    Node.js 工具模块-OS模块+path模块
    Node.js GET/POST请求
    Canvas动画+canvas离屏技术
    Python OS 模块
    Python random 模块
    Python time 模块
    Python 迭代器
    Python 生成器
  • 原文地址:https://www.cnblogs.com/qwn34/p/13933055.html
Copyright © 2011-2022 走看看