• Mold


    #include <stdio.h>
    #include <stdlib.h>
    
    #define SIZE 1000
    int map[SIZE+2][SIZE+2]={0};
    int run_test(const char data[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(data[i][j]!=0)map[i+1][j+1]++;
            }
        }
        int count=0;
        for(int i=1;i<SIZE+1;i++){
            for(int j=1;j<SIZE+1;j++){
                if(map[i][j]==1&&map[i+1][j]==1&&map[i][j+1]==1&&map[i+1][j+1]==1){
                        count++;
                        map[i][j]=0;map[i+1][j]=0;
                        map[i][j+1]=0;map[i+1][j+1]=0;
                }
                if(map[i][j]==1&&map[i+1][j]==1&&map[i+1][j+1]==1){
                        count++;
                        map[i][j]=0;map[i+1][j]=0;
                        map[i+1][j+1]=0;
                }
                if(map[i][j]==1&&map[i+1][j]==1&&map[i][j+1]==1){
                        count++;
                        map[i][j]=0;map[i+1][j]=0;
                        map[i][j+1]=0;
                }
                if(map[i][j]==1&&map[i][j+1]==1&&map[i+1][j+1]==1){
                        count++;
                        map[i][j]=0;
                        map[i][j+1]=0;map[i+1][j+1]=0;
                }
                if(map[i][j]==0&&map[i+1][j]==1&&map[i][j+1]==1&&map[i+1][j+1]==1){
                        count++;
                        map[i+1][j]=0;
                        map[i][j+1]=0;map[i+1][j+1]=0;
                }
                if(map[i][j]==1&&map[i+1][j]==1){
                        count++;
                        map[i][j]=0;map[i+1][j]=0;
                }
                if(map[i][j]==1&&map[i][j+1]==1){
                        count++;
                        map[i][j]=0;
                        map[i][j+1]=0;
                }
                if(map[i][j]==1){
                    count++;
                    map[i][j]=0;
                }
            }
        }
        return count;
    }
    
    
    MoldType CheckMold(char data[SIZE][SIZE], int x, int y)
    {
        if((x+1<=SIZE)&&(y+1<=SIZE)&&data[x][y]&&data[x][y+1]&&data[x+1][y]&&data[x+1][y+1]) 
        {
            data[x][y]=0;
            data[x][y+1]=0;
            data[x+1][y]=0;
            data[x+1][y+1]=0;
            return ABCD;
        }
        else if((x+1<=SIZE)&&(y+1<=SIZE)&&data[x][y]&&data[x][y+1]&&data[x+1][y])
        {
            data[x][y]=0;
            data[x][y+1]=0;
            data[x+1][y]=0;
            return ABC;
        }
        else if((x+1<=SIZE)&&(y+1<=SIZE)&&data[x][y]&&data[x][y+1]&&data[x+1][y+1])
        {
            data[x][y]=0;
            data[x][y+1]=0;
            data[x+1][y+1]=0;
            return ABD;
        }
        else if((x+1<=SIZE)&&(y+1<=SIZE)&&data[x][y]&&data[x+1][y]&&data[x+1][y+1])
        {
            data[x][y]=0;
            data[x+1][y]=0;
            data[x+1][y+1]=0;
            return ACD;
        }
        else if((x+1<=SIZE)&&(y+1<=SIZE)&&!data[x][y]&&data[x][y+1]&&data[x+1][y]&&data[x+1][y+1])
        {
            data[x][y+1]=0;
            data[x+1][y]=0;
            data[x+1][y+1]=0;
            return BCD;
        }
        else if((y+1<=SIZE)&&data[x][y]&&data[x][y+1])
        {
            data[x][y]=0;
            data[x][y+1]=0;
            return AB;
        }
        else if((x+1<=SIZE)&&data[x][y]&&data[x+1][y])
        {
            data[x][y]=0;
            data[x+1][y]=0;
            return AC;
        }
        else if(data[x][y])
        {
            data[x][y]=0;
            return A;
        }
        else return NONE;
    }
    int run_test( char data[SIZE][SIZE])
    {
        int count=0;
        for(int i=0; i<SIZE; i++)
        {
            for(int j=0; j<SIZE; j++)
            {
                MoldType result = CheckMold(data, i, j);
                if(result!=NONE)count++;
            }
            //DrawArray(data);
        }
        return count;
    }
    
    
    
    
    static char data[10][SIZE][SIZE];
    
    
    void build_data(void)
    {
        static char virus[8][4][4] = 
        {
            {{ 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }},
            {{ 0, 0, 0, 0 }, { 0, 1, 1, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }},
            {{ 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 }},
            {{ 0, 0, 0, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 }},
            {{ 0, 0, 0, 0 }, { 0, 1, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 0 }},
            {{ 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 1, 0 }, { 0, 0, 0, 0 }},
            {{ 0, 0, 0, 0 }, { 0, 0, 1, 0 }, { 0, 1, 1, 0 }, { 0, 0, 0, 0 }},
            {{ 0, 0, 0, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 0, 0, 0 }}
        };
    
        for (int l = 0; l < 10; l++)
        {
            for (int y = 0; y < SIZE; y++)
                for (int x = 0; x < SIZE; x++)
                    data[l][x][y] = 0;
    
            for (int c = 0; c < SIZE * SIZE; c++)
            {
                int x = rand() % (SIZE - 4);
                int y = rand() % (SIZE - 4);
                int t = rand() % 8;
    
                for (int cy = 0; cy < 4; cy++)
                    for (int cx = 0; cx < 4; cx++)
                        data[l][x + cx][y + cy] = virus[t][cx][cy];
            }
        }
    }
    
    
    void main(int argc, char* argv[])
    {
        build_data();
    
        for (int c = 0; c < 10; c++)
            printf("%d
    ", run_test(data[c]));
    }
  • 相关阅读:
    vue项目开发基本目录结构
    小程序图片上传七牛
    vue2.0无限滚动加载数据插件
    Vue使用vue-echarts图表
    vue-countTo---简单好用的一个数字滚动插件
    vee-validate的使用
    javaScript---RegExp
    JavaScript 特效之四大家族(offset/scroll/client/event)
    CSS3 三次贝塞尔曲线(cubic-bezier)
    require和import区别
  • 原文地址:https://www.cnblogs.com/ZzznOoooo/p/6628082.html
Copyright © 2020-2023  润新知