• Cross


    #include <stdio.h>
    #include <stdlib.h>
    
    #define SIZE 500
    static char map[10][SIZE][SIZE]={0};
    
    int run_test(const char map[SIZE][SIZE]);
    
    
    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]));
    	return;
    }
    
    int run_test(const char map[SIZE][SIZE])
    
    {
    	int data[SIZE][SIZE];
    	int max=0;
    	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 rl=false;
    				bool ud=false;
    				if( j+1<SIZE && data[i][j+1]){
    					rl=true;
    				}
    				if( j-1>=0 && data[i][j-1]){
    					rl=true;
    				}
    				if(i+1<SIZE && data[i+1][j]){
    					ud=true;
    				}
    				if(i-1>=0 && data[i-1][j]){
    					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;
    		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;
    }
    

    four lines intersect in a map of size 6*6.

    the length of lines excluding intersections,You can see that the length of the longest line is 2.

    the thickness of lines is always 1,and lines cross/intersect each other at right angles.

  • 相关阅读:
    封装logging模块,创建日志器
    excel的读写封装,利用openpyxl
    利用yaml封装配置文件模块
    自动生成小学四则运算项目(更新)
    基于cmmi的软件工程及实训指导 第一章 读后感
    第一次数据库学习
    第一个爬虫和测试
    预测球队成绩
    第一个网页
    科学计算与可视化
  • 原文地址:https://www.cnblogs.com/ZzznOoooo/p/6656600.html
Copyright © 2020-2023  润新知