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

贡献了好几个WA,总算AC了,第一个算法题,庆祝。。。。

Posted by like680623 at 2010-11-23 21:08:38 on Problem 2488
#include<stdio.h>
#include<string.h>
#define MAXN  26
#define N      1500
void bfs(int m, int n);
int  queue[N];
int  front, rear, l;
int  visit[MAXN + 3][MAXN + 3];
int main()
{
	int total, p, q,  i, j , k , s, d;
	scanf ("%d", &total);
	for (i = 1; i <= total; i++)
	{
		front = rear = 0;
		memset(visit, 0, sizeof (visit));
		scanf("%d%d", &p, &q);
		l = p * q * 2;
		for (j = 1; j <= p; j++)
			for (k = 1; k <= q; k++)
				visit[j][k] = 1;
		bfs(1, 1);
		--rear;
		printf("Scenario #%d:\n", i);
		if (rear + 1 != l)
			printf("impossible");
		else{
				while (rear >= front)
				{
					if (front % 2 == 0)
						printf("%c", queue[front]);
					else 
						printf("%d", queue[front]);
					front++;
				}
		}
			if (i != total)
					printf("\n\n");
			else printf("\n");
		}
	return 0;
}

void bfs(int m, int n)
{
	if (m < 0 || n < 0) return;
	if (!visit[m][n]) return ;
	visit[m][n] = 0;
	queue[rear++] = n - 1 + 'A';
	queue[rear++] = m ;
	bfs(m  - 1, n  - 2);
	bfs(m + 1, n  - 2);
	bfs(m  - 2, n  - 1);
	bfs(m + 2, n  - 1);
	bfs(m  - 2, n + 1);
	bfs(m + 2, n + 1);
	bfs(m  - 1, n + 2);
	bfs(m + 1, n + 2);
	if (rear  != l)
	{
		rear -= 2;
		visit[m][n] = 1;
	}
	return ;
}

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