1511: The Imperfect chessboard
Time limit:1 Sec Memory limit:128 MB
submit:169 solved:56
[Submit] [Status] [Web Board] Description]
Input
The input contains no more than 10000 sets of data. Each set of data contains 6 integers r1, C1, R2, C2, R3, C3 (1<=r1, C1, R2, C2, R3, c3<=8). Three lattice A, B, C are guaranteed to be different.
Output
For each set of data, the test point number and the minimum number of steps are output.
Sample Input
1 1 8 7 5 6
1 1 3 3 2 2
Sample Output
Case 1:7
Case 2:3
Last year, the province of a basic problem, that is, in this place card a bit, leading to pass with the medal, recently did not brush the problem, take this problem to practice practiced hand, found that the idea is very clear, check the code for a long time, found no running results. Very basic problem ah, should not take the time. The last discovery was that there was a mistake in the logic statement, putting | | Misuse into && This peacetime also did not careful, led to check for a long time to find here error, later to deserve attention.
The following is the code for AC:
Array simulation queue of BFS
#include <cstdio>#include <cstring>structqueue{intX,y,count;};structQueue q[ +];intvisit[9][9];//This array is going to be a little bigger.intdir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,-1},{1,1},{-1,1},{-1,-1}};//Direction arrayintC2,C3,R2,R3;intBFsintXintY) {intFront=0, rear=0;structQueue que;intFx,fy; Q[rear].x=x; Q[rear].y=y; Q[rear++].count=0; visit[x][y]=1; while(front<rear) {que=q[front++];if(QUE.X==R2 && QUE.Y==C2) {returnQue.count; } for(intI=0; i<8; i++) {fx=que.x+dir[i][0]; fy=que.y+dir[i][1];if(fx>0&&fy>0&&fx<=8&&fy<=8&&!visit[fx][fy] && (FX!=R3 | | fy!=c3)) {visit[fx][fy]=1;//Tag AccessQ[REAR].X=FX;//QueueQ[rear].y=fy; q[rear++].count=que.count+1; } } }}intMain () {intc1,r1,sum,k=1; while(scanf("%d%d%d%d%d%d", &R1,&C1,&R2,&C2,&R3,&C3)!=eof) {memset(Visit,0,sizeof(visit)); SUM=BFS (R1,C1);printf("Case%d:%d\n", k++,sum); }return 0;}
STL queue, this does not know where there is a little problem, has not been able to AC
#include <cstdio>#include <queue>#include <cstring>using namespace STD;structnode{intX,y,count;}; queue<node>Qintvisit[Ten][Ten];intdir[8][2]= {{1,0},{-1,0},{0,1},{0,-1},{1,-1},{1,1},{-1,1},{-1,-1}};intC2,C3,R2,R3;intBFsintXintY) {node front,rear;intDx,dy; Front.x=x; Front.y=y; Front.count=0; visit[x][y]=1; Q.push (front); while(!q.empty ()) {Front=q.front (); Q.pop ();if(FRONT.X==R2 && FRONT.Y==C2) {returnFront.count; } for(intI=0;i<8; i++) {dx=front.x+dir[i][0]; dy=front.y+dir[i][1];if(dx>0&&dy>0&&dx<=8&&dy<=8&&!visit[dx][dy] && (DX!=R3 | | dy!=c3)) {visit[dx][dy]=1;//Tag AccessREAR.X=DX; Rear.y=dy; rear.count=front.count+1; Q.push (rear); } } }}intMain () {intc1,r1,sum,k=1; while(scanf("%d%d%d%d%d%d", &R1,&C1,&R2,&C2,&R3,&C3)!=eof) {memset(Visit,0,sizeof(visit)); SUM=BFS (R1,C1);printf("Case%d:%d\n", k++,sum); }return 0;}
The tenth session of Hunan Province College students computer Program design competition: Incomplete chessboard