• ranch


    #include <stdio.h>
    #include <stdlib.h>
    
    #define SIZE 100
    int map[SIZE+2][SIZE+2]={0};
    int run_test(char ranch[SIZE][SIZE])
    {
        for(int i=0;i<SIZE+2;i++){
            for(int j=0;j<SIZE+2;j++){
                map[i][j]=0;
            }
        }
        for(int i=0;i<SIZE;i++){
            for(int j=0;j<SIZE;j++){
                if(ranch[i][j]=='+')map[i+1][j+1]=1;
            }
        }
        
        int count=11;
        for(int i=1;i<SIZE+1;i++){
            for(int j=1;j<SIZE+1;j++){
                if(map[i][j]==0){
                    bool flag=false;
                    map[i][j]=count;
                    if(map[i-1][j-1]==0){map[i-1][j-1]=count;flag=true;}
                    if(map[i-1][j]==0){map[i-1][j]=count;flag=true;}
                    if(map[i-1][j+1]==0){map[i-1][j+1]=count;flag=true;}
                    if(map[i][j-1]==0){map[i][j-1]=count;flag=true;}
                    if(map[i][j+1]==0){map[i][j+1]=count;flag=true;}
                    if(map[i+1][j-1]==0){map[i+1][j-1]=count;flag=true;}
                    if(map[i+1][j]==0){map[i+1][j]=count;flag=true;}
                    if(map[i+1][j+1]==0){map[i+1][j+1]=count;flag=true;}
                    while(flag){
                        for(int x=i;x<SIZE+1;x++){
                            for(int y=1;y<SIZE+1;y++){
                                if(map[x][y]==count){
                                    flag=false;
                                    if(map[x-1][y-1]==0){map[x-1][y-1]=count;flag=true;}
                                    if(map[x-1][y]==0){map[x-1][y]=count;flag=true;}
                                    if(map[x-1][y+1]==0){map[x-1][y+1]=count;flag=true;}
                                    if(map[x][y-1]==0){map[x][y-1]=count;flag=true;}
                                    if(&map[x][y+1]==0){map[x][y+1]=count;flag=true;}
                                    if(map[x+1][y-1]==0){map[x+1][y-1]=count;flag=true;}
                                    if(map[x+1][y]==0){map[x+1][y]=count;flag=true;}
                                    if(map[x+1][y+1]==0){map[x+1][y+1]=count;flag=true;}
                                }
                            }
                        }
                    }
                    count++;
                }
            }
        }
        
    
            return count-11;
            return 0;
    }
    
    
    void main(void)
    {
        static char ranch[SIZE][SIZE];
    
        for (int c = 0; c < 10; c++)
        {
            for (int y = 0; y < SIZE; y++)
                for (int x = 0; x < SIZE; x++)
                    ranch[x][y] = ' ';
    
            for (int c = 0; c < 10000; c++)
                ranch[rand() % 100][rand() % 100] = '+';
    
            printf("%d
    ", run_test(ranch));
        }
    }
  • 相关阅读:
    React Native For Android 环境搭建
    MySql 打开日志文件
    PHP使用JSON通信
    PHPStorm 调式JS /同时调式PHP和jS
    PHP list,explode的使用
    PHP foreach使用
    PHP eof的使用
    使用Spring缓存的简单Demo
    android源码的目录结构
    在Ubuntu上安装LAMP服务器
  • 原文地址:https://www.cnblogs.com/ZzznOoooo/p/6628089.html
Copyright © 2020-2023  润新知