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

状态记录算法是16ms,求问此模拟题0ms的算法,请赐教。(附上本人代码)

Posted by scuwf at 2011-11-14 11:07:12 on Problem 1099
#include<stdio.h>
#define MAXSIZE 11
typedef struct
{
	int right;
	int down;
}Status;
int main()
{
	int casecount=0,n,i,j;
	int a[MAXSIZE][MAXSIZE];
	char outm[4*MAXSIZE-3][4*MAXSIZE+2];
	Status status[MAXSIZE+1][MAXSIZE+1];
	for(i=0;i<MAXSIZE;i++) status[i][0].right=-1;
	for(j=0;j<MAXSIZE;j++) status[0][j].down=1;
	while(scanf("%d",&n) && n)
	{
		for(i=0;i<4*n-3;i++) outm[i][4*n+1]='\0';
		for(i=0;i<4*n-3;i++)
		{
			for(j=0;j<4*n+1;j++) outm[i][j]=' ';
		}
		casecount++;
		printf("Case %d:\n\n",casecount);
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++) scanf("%d",&a[i][j]);
		}
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				if(a[i][j]==1)
				{
					outm[4*i][4*j+2]='O';
					outm[4*i][4*j]='H';
					outm[4*i][4*j+1]='-';
					outm[4*i][4*j+3]='-';
					outm[4*i][4*j+4]='H';
					status[i][j+1].right=1;
					status[i+1][j].down=-1;
				}
				else if(a[i][j]==-1)
				{
					outm[4*i][4*j+2]='O';
					outm[4*i-2][4*j+2]='H';
					outm[4*i-1][4*j+2]='|';
					outm[4*i+1][4*j+2]='|';
					outm[4*i+2][4*j+2]='H';
					status[i][j+1].right=-1;
					status[i+1][j].down=1;
				}
				else
				{
					if(status[i][j].right==-1)
					{
						outm[4*i][4*j+2]='O';
						outm[4*i][4*j+1]='-';
						outm[4*i][4*j]='H';
						status[i][j+1].right=-1;
					}
					else
					{
						outm[4*i][4*j+2]='O';
						outm[4*i][4*j+3]='-';
						outm[4*i][4*j+4]='H';
						status[i][j+1].right=1;
					}
					if(status[i][j].down==-1)
					{
						outm[4*i][4*j+2]='O';
						outm[4*i-2][4*j+2]='H';
						outm[4*i-1][4*j+2]='|';
						status[i+1][j].down=-1;
					}
					else
					{
						outm[4*i][4*j+2]='O';
						outm[4*i+2][4*j+2]='H';
						outm[4*i+1][4*j+2]='|';
						status[i+1][j].down=1;
					}
				}
			}
		}
		for(i=0;i<4*n+3;i++) printf("*");
		printf("\n");
		for(i=0;i<4*n-3;i++) printf("*%s*\n",outm[i]);
		for(i=0;i<4*n+3;i++) printf("*");
		printf("\n");
		printf("\n");
	}
	return 0;
}

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