zoukankan      html  css  js  c++  java
  • 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));
        }
    }
  • 相关阅读:
    软件工程个人作业(4)
    软件工程个人作业(3)
    软件工程个人作业(2)
    软件工程个人作业(1)
    构建之法
    消息分发机制,实现战场与UI通信功能
    设置父物体方法(包括层级)
    NGUI通过点击按钮来移动面板位置,实现翻页功能
    unity中调用android的剪切板
    屏蔽UI事件
  • 原文地址:https://www.cnblogs.com/ZzznOoooo/p/6628089.html
Copyright © 2011-2022 走看看