• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
crucio
博客园    首页    新随笔    联系   管理    订阅  订阅
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\n", run_test(ranch));
    }
}

 

posted on 2017-03-27 18:15  crucio  阅读(348)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3