• Cross


    #include <stdio.h>
    #include <stdlib.h>
    
    #define SIZE 1000
    
    static char map[10][SIZE][SIZE];
    
    /*
    int data[SIZE][SIZE];
    int run_test(const char map[SIZE][SIZE])
    {
        for(int i=0;i<SIZE;i++){
            for(int j=0;j<SIZE;j++){
                data[i][j]=map[i][j];
            }
        }
        for(int i=0;i<SIZE;i++){
            for(int j=0;j<SIZE;j++){
                if(data[i][j]==1){
                    bool ud=false;
                    bool rl=false;
                    if(i>0&&data[i-1][j]==1)rl=true;
                    if(i+1<SIZE&&data[i+1][j]==1)rl=true;
                    if(j>0&&data[i][j-1]==1)ud=true;
                    if(j+1<SIZE&&data[i][j+1]==1)ud=true;
                    if(rl&&ud==1)data[i][j]=0;
                }
            }
        }
        
        int max=0;
        for(int i=0;i<SIZE;i++){
            for(int j=0;i<SIZE;j++){
                int x=0;
                int y=0;
                if(data[i][j]==1){
                    while(data[i+x][j]!=0)x++;
                    while(data[i][j+y]!=0)y++;
                    if(x>max)max=x;
                    if(y>max)max=y;
                }
            }
        }
        return max; // 가장 긴 선분의 길이
    }
    /*
    int run_test(const char map[SIZE][SIZE])
    {    
        int l=0;
        int max1=0;
        int max2=0;
        int b=0;
        for(int i=0;i<SIZE;i++)
        {
            for(int j=0;j<SIZE;j++)
            {
                if(map[i][j]==0||map[i-1][j]==1||map[i+1][j]==1)
                {
                    l=0;
                }
                else
                {
                    l++;
                    if(l>max1)max1=l;
                }
            }
        }
        for(int j=0;j<SIZE;j++)
        {
            for(int i=0;i<SIZE;i++)
            {
                if(map[i][j]==0||map[i][j-1]==1||map[i][j+1]==1)
                {
                    l=0;
                }
                else
                {
                    l++;
                    if(l>max2)max2=l;
                }
            }
        }
        if(max1>=max2) b=max1;
        else b=max2;
        return b;
    }
    */
    int data[SIZE][SIZE];
    int run_test(  const char map[SIZE][SIZE])
    {
        for(int i=0;i<SIZE;i++)
        for(int j=0;j<SIZE;j++) 
        {
            data[i][j]=map[i][j];
        }
        int len=0;
        for(int i=0;i<SIZE;i++)
        for(int j=0;j<SIZE;j++) 
        {
            if(data[i][j]==1)
            {
            bool UD=false;
            bool RL=false;
            if(j+1<SIZE&&data[i][j+1]==1) {RL=true;}
            if(data[i][j-1]==1&&j>0) {RL=true;}
            if(data[i+1][j]==1&&j+1<SIZE){UD=true;}
            if(data[i-1][j]==1&&i>0) {UD=true;}
            if(RL&&UD==1) data[i][j]=0;
            }
        }
        for(int i=0;i<SIZE;i++)
        for(int j=0;j<SIZE;j++)
        {
            int x=0;
            int y=0;
            if(data[i][j]==1)
            while(data[i+x][j]!=0) x++;                                                              
            while(data[i][j+y]!=0) y++;
            if(x>len) len=x;
            if(y>len) len=y;
    
    
        }
    
        return len; // 가장 긴 선분의 길이
    }
    
    
    void build_map(void)
    {
        for (int c = 0; c < 10; c++)
        {
            for (int y = 0; y < SIZE; y++)
                for(int x = 0; x < SIZE; x++)
                    map[c][x][y] = 0;
    
            for (int x = rand() % 10; x < SIZE; x += 2 + rand() % 8)
                for (int sy = rand() % SIZE, ey = rand() % SIZE; sy < ey; )
                    map[c][x][sy++] = 1;
    
            for (int y = rand() % 10; y < SIZE; y += 2 + rand() % 8)
                for (int sx = rand() % SIZE, ex = rand() % SIZE; sx < ex; )
                    map[c][sx++][y] = 1;
        }
    }
    
    void main(void)
    {
        build_map();
    
        for (int count = 0; count < 10; count++)
            printf("%d
    ", run_test(map[count]));
    }
  • 相关阅读:
    我使用的Chrome插件列表
    从花式swap引出的pointer aliasing问题
    CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组
    CF #335 div1 A. Sorting Railway Cars
    Mac 下载安装MySQL
    Mac 安装Tomcat
    CF #CROC 2016
    安全体系(零)—— 加解密算法、消息摘要、消息认证技术、数字签名与公钥证书
    安全体系(一)—— DES算法详解
    JAVA实现用户的权限管理
  • 原文地址:https://www.cnblogs.com/ZzznOoooo/p/6628063.html
Copyright © 2020-2023  润新知