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 |
//memset(visit, 0, sizeof(0)); //天呐天呐 谁告诉我为什么这行不行!!!!!!!!!!!!!!!!!1#include<iostream> using namespace std; int main() { freopen("in.txt", "r", stdin); char a, c, b, d; int i; int begin_i, end_i, begin_j, end_j; int Row[65]; int Col[65]; int row, col; int rear, front, temp, que[65]; int visit[65][65]; int move[8][2] = {{-2, -1}, {-2, 1}, {-1, -2}, {-1, 2}, {1, -2}, {1, 2}, {2, -1}, {2, 1}}; while(cin >> a >> b >> c >> d) { //输入方式有诸多疑问 begin_i = a - 'a', begin_j = b - '1', end_i = c - 'a', end_j = d - '1'; for(i = 0; i < 8; i ++) for(int j = 0; j < 8; j ++) visit[i][j] = 0; //非要这样写?memset不行??????? //memset(visit, 0, sizeof(0)); //天呐天呐 谁告诉我为什么这行不行!!!!!!!!!!!!!!!!!1 front = rear = 0; Row[0] = begin_i; Col[0] = begin_j; que[rear ++] = 0; visit[begin_i][begin_j] = 1; while(front < rear) { temp = front ++; if(Row[temp] == end_i && Col[temp] == end_j) break; for(i = 0; i < 8; i ++) { row = Row[temp] + move[i][0]; col = Col[temp] + move[i][1]; if(row >= 0 && col >= 0 && row < 8 && col < 8 && visit[row][col] == 0) { visit[row][col] = 1; Row[rear] = row; Col[rear] = col; que[rear ++] = que[temp] + 1; //cout << temp << endl; } } } cout << que[temp] << endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator