首页 > 其他 > 详细

Cross - -

时间:2017-04-01 16:47:52      阅读:125      评论:0      收藏:0      [点我收藏+]
#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\n",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.

Cross - -

原文:http://www.cnblogs.com/ZzznOoooo/p/6656600.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!