Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贡献了好几个WA,总算AC了,第一个算法题,庆祝。。。。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator