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;
    }
  • 相关阅读:
    MyEclipse中无法将SVN检出来的项目部署到tomcat中
    Hibernate n+1问题
    Dubbox框架和Zookeeper 依赖的引入
    SpringSecurity安全框架
    order
    旅游网数据库
    教学所用
    权限系统设计五张表
    springMVC上传文件
    web 开发流程
  • 原文地址:https://www.cnblogs.com/qwn34/p/13933055.html
Copyright © 2011-2022 走看看