Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的思路 并附代码

Posted by 201101050424 at 2012-01-05 20:44:14 on Problem 1099
对于0的 H20 如果左边没有H  那么右边一定有H   如果上边没有H  那下面的H 属于自己


#include <stdio.h>
#include <string.h>
int main()
{
	char map[200][200];
	int k;
	int a[100][100];
	int i,j,m,n;
	int count=0;
	freopen("input.txt","r",stdin);
	scanf("%d",&k);
	while(k!=0)
	{
		memset(map,' ',sizeof(map));
		for(i=1;i<=k;i++)
		{
			for(j=1;j<=k;j++)
			{
				scanf("%d",&a[i][j]);
			}
		}
		m=1;
		for(i=1;i<=4*(k-1)+1;)
		{
			n=1;
			for(j=3;j<=4*k-1;)
			{
				map[i][j]='O';
				if(a[m][n]==1)
				{
					map[i][j+1]='-';
					map[i][j+2]='H';
					map[i][j-1]='-';
					map[i][j-2]='H';
				}
				else if(a[m][n]==-1)
				{
					map[i-1][j]='|';
					map[i-2][j]='H';
					map[i+1][j]='|';
					map[i+2][j]='H';
				}
				j=j+4;
				n++;
			}
			i=i+4;
			m++;
		}
		m=1;
		for(i=1;i<=4*(k-1)+1;)
		{
			if(i==1)
			{
				n=1;
				for(j=3;j<=4*k-1;)
				{
					if(a[m][n]!=0)
					{				
						j=j+4;
						n++;
						continue;
					}
					if(map[i][j-2]==' ')
					{
						map[i][j-1]='-';
						map[i][j-2]='H';
					}
					else
					{
						map[i][j+1]='-';
						map[i][j+2]='H';
					}
					map[i+1][j]='|';
					map[i+2][j]='H';
					j=j+4;
					n++;
				}
			}
			else if(i!=1&&i!=4*(k-1)+1)
			{
				n=1;
				for(j=3;j<=4*k-1;)
				{
					if(a[m][n]!=0)
					{   
						j=j+4;
						n++;
						continue;
					}
					if(map[i][j-2]==' ')
					{
						map[i][j-1]='-';
						map[i][j-2]='H';
					}
					else
					{
						map[i][j+1]='-';
						map[i][j+2]='H';
					}
					if(map[i-2][j]==' ')
					{
						map[i-1][j]='|';
						map[i-2][j]='H';
					}
					else
					{
						map[i+1][j]='|';
						map[i+2][j]='H';
					}
					j=j+4;
					n++;
				}

			}
			else if(i==4*(k-1)+1)
			{
				n=1;
				for(j=3;j<=4*k-1;)
				{
				    if(a[m][n]!=0)
					{
						j=j+4;
						n++;
						continue;
					}
					if(map[i][j-2]==' ')
					{
						map[i][j-1]='-';
						map[i][j-2]='H';
					}
					else
					{
						map[i][j+1]='-';
						map[i][j+2]='H';
					}
					map[i-1][j]='|';
					map[i-2][j]='H';				
					j=j+4;
					n++;
				}
			}
			i=i+4;
			m++;
		}
		count++;
		if(count!=1)
		{
			printf("\n");
		}
		printf("Case %d:\n\n",count);
		for(i=1;i<=4*(k-1)+1;i++)
		{
			if(i==1)
			{
				for(j=1;j<=4*k+3;j++)
				{
					printf("*");
				}
				printf("\n");
			}
			for(j=1;j<=4*k+1;j++)
			{
				if(j==1)
				{
					printf("*");
				}
				printf("%c",map[i][j]);
			}
			printf("*\n");
		}
		for(j=1;j<=4*k+3;j++)
		{
			printf("*");
		}
		printf("\n");
		scanf("%d",&k);
	}
}





Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator