Problem 1005 求帮忙找测试案例

rw13420132 | 2015-05-24 21:31:48Author
#include <iostream> #include <cstring> #include <queue> using namespace std; struct Piont { int x ,y; }; int zy[8] = { 1 ,1 ,-1 ,-1 ,2 ,2 ,-2 ,-2 }; int zx[8] = { 2 ,-2 ,2 ,-2 ,1 ,-1 ,1 ,-1 }; int counnt ,bz[1000][1000] ,n ,m ,k; Piont w ,s; void BFS () { queue<Piont>q; q.push ( w ); bz[w.x][w.y] = 1; Piont e ,d; int i ,size; size = 1; counnt++; while ( !q.empty () ) { if ( size == 0 ) { counnt++; size = q.size (); } if ( counnt > k )return; e = q.front (); q.pop (); size--; for ( i = 0; i < 8; i++ ) { d.x = e.x + zx[i]; d.y = e.y + zy[i]; if ( 0<d.x&&d.x <= n&&d.y > 0 && d.y <= m ) { if ( s.x - counnt <= d.x && d.x <= s.x + counnt&&d.y >= s.y - counnt && d.y <= s.y + counnt ) { if ( counnt == 1 && d.x == s.x&&d.y == s.y )counnt++; return; } if ( bz[d.x][d.y] == 0 ) { q.push ( d ); bz[d.x][d.y] = 1; } } } } } int main () { int x ,g; g = 1; cin >> x; while (x--) { memset ( bz ,0 ,sizeof( bz ) ); counnt = 0; cin >> n >> m >> k; cin >> s.x >> s.y; cin >> w.x >> w.y; BFS (); cout << "Case #" << g++ << ":" << endl; if ( counnt > 0 && counnt <= k )cout << counnt << endl; else cout << "OH,NO!" << endl; } return 0; }
rw13420132 | 2015-05-24 21:36:11# 1
走到第几步国王就能到达在原点周边横纵坐标加减几的范围(一步时不能回到原点,其他步数都可以),只要判断侍卫是否走到国王能到达的范围就能解出来!不过WA了