The tenth session of Hunan Province College students computer Program design competition: Incomplete chessboard

Source: Internet
Author: User

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", &AMP;R1,&AMP;C1,&AMP;R2,&AMP;C2,&AMP;R3,&AMP;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", &AMP;R1,&AMP;C1,&AMP;R2,&AMP;C2,&AMP;R3,&AMP;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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.