고전 c 프로그램(0032)-미궁 타당성 분석

3034 단어
/************************************************************************************** 
* Function     : test
* Create Date  : 2014/07/11
* Author       : NTSK13 
* Email        : [email protected] 
* Copyright    :  , 。 
*                  
* Version      : V0.1                    
***************************************************************************************
 c (0032)

 :   10*10  ,

 1, , 0.

0 ,1 

 :

1 0 0 1 0 1 0 0 0 0
1 1 0 1 0 1 0 0 0 0
0 1 1 1 1 1 1 0 0 0
1 0 0 0 0 1 0 0 0 0
1 1 1 1 1 1 1 0 0 0
0 0 1 0 0 0 0 0 0 0
1 0 1 0 1 1 1 1 1 1
1 1 1 0 1 0 0 1 0 0
0 0 1 1 1 0 1 1 1 0
0 0 1 0 1 1 0 0 1 1  
     
**************************************************************************************/  
#include<stdio.h>

#define M 10

typedef struct{
	int x;
	int y;
}Pos;

Pos start,end;

int data[M][M];
/***********************************************************/
int offset[4][2]={-1,0,0,1,1,0,0,-1};
int mark[M][M];

int check(Pos start,Pos end);
/***********************************************************/
int main(void)
{
	int test_case;
	int T=0,th=0;
	/*
	   The freopen function below opens input.txt file in read only mode, and afterward,
	   the program will read from input.txt file instead of standard(keyboard) input.
	   To test your program, you may save input data in input.txt file,
	   and use freopen function to read from the file when using scanf function.
	   You may remove the comment symbols(//) in the below statement and use it.
	   But before submission, you must remove the freopen function or rewrite comment symbols(//).
	 */
	 freopen("input.txt", "r", stdin);
	/*
	   If you remove the statement below, your program's output may not be rocorded
	   when your program is terminated after the time limit.
	   For safety, please use setbuf(stdout, NULL); statement.
	 */
	setbuf(stdout, NULL);

	scanf("%d", &T);

	for(test_case = 0; test_case < T; test_case++)
	{
		int ret=0,i=0,j=0;
		/**********************************
		 * Implement your algorithm here. */
		scanf("%d", &th);
		for(i=0;i<M;i++)
		for(j=0;j<M;j++)
		{
			scanf("%d",&data[i][j]);
			mark[i][j]=0;
		}
		start.x=0;
		start.y=0;
		end.x=9;
		end.y=9;

		ret=check(start,end);
		
		/**********************************/
		// Print the answer to standard output(screen).
		printf("#%d %d
",th,ret); fflush(stdout);// Eclipse printf() bug } return (0);//Your program should return 0 on normal termination. } int check(Pos start,Pos end) { int x=0,y=0,tx=0,ty=0,k=0,ret=0; x=start.x; y=start.y; if(x==end.x && y==end.y) return 1; mark[x][y]=1; for(k=0;k<4;k++) { tx=x+offset[k][0]; ty=y+offset[k][1]; if( tx>=0 && tx<M && ty>=0 && ty<M && mark[tx][ty]==0 ) { if(data[tx][ty]==1) { start.x=tx; start.y=ty; ret=check(start,end); if(ret==1) return ret; } } } return ret; }

좋은 웹페이지 즐겨찾기