E D R , A S I H C RSS

AKnight'sJourney (rev. 1.6)

AKnight's Journey

Describe AKnight'sJourney here

Source Code

#include <stdio.h>
#include <memory.h>

int A[30][30];
int B[30][2];
int P, Q;
short Flag;

void R(int n, int p, int q)
{
	if(Flag || 1>p || p>P || 1>q || q>Q || A[p][q]){
		return;
	}else if(n==P*Q){
		B[n][0]=p;
		B[n][1]=q;

		Flag=1;

		return;
	}else{
		B[n][0]=p;
		B[n][1]=q;
		A[p][q]=n;

		R(n+1, p-1, q-2);
		R(n+1, p+1, q-2);
		R(n+1, p-2, q-1);
		R(n+1, p+2, q-1);
		R(n+1, p-2, q+1);
		R(n+1, p+2, q+1);
		R(n+1, p-1, q+2);
		R(n+1, p+1, q+2);

		A[p][q]=0;

		return;
	}
}

int main()
{
	int n, i, j;

	scanf("%d", &n);
	for(i=1;i<=n;i++){
		scanf("%d %d", &P, &Q);
		
		Flag=0;
		memset(A, 0, sizeof(A));
		R(1, 1, 1);

		printf("Scenario #%d:\n", i);
		if(Flag){
			for(j=1; j<=P*Q; j++){
				printf("%c%c", B[j][1]+'A'-1, B[j][0]+'0');
			}
		}else{
			printf("impossible");
		}
		puts("\n");
	}

	return 0;
}


/// C

...


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:21
Processing time 0.0421 sec