Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大家帮忙看看!!

Posted by o00o at 2008-06-12 23:37:05 on Problem 2243
#include<stdio.h>
#include<stdlib.h>
struct node
{
    int key;
    int depth;
};
int chess[8][8],qb,qe,qsize;
node queue[65];//queue数组开65 ac,开64却run time error,why?
int main()
{
//    freopen("in.txt","r",stdin);
    int i,j,k,depth,r,c,target;
    char sb[3],se[3];
    while(scanf("%s %s",sb,se)!=EOF)
    {    
        for(i=0;i<8;i++)
            for(j=0;j<8;j++)
                chess[i][j]=0;
        queue[0].key=8*(sb[1]-'0'-1)+(sb[0]-'a');
        queue[0].depth=0;
        qb=0;
        qe=1;
        qsize=1;
        target=8*(se[1]-'0'-1)+(se[0]-'a');
        while(qsize>0)
        {
            k=queue[qb].key;
            depth=queue[qb].depth;
            qb++;
            qsize--;
            if(k==target)
            {
                printf("To get from %s to %s takes %d knight moves.\n",sb,se,depth);
                break;
            }
            r=k/8;
            c=k%8;
            if(r>=1&&c>=2&&chess[r-1][c-2]==0)
            {
                chess[r-1][c-2]=1;
                queue[qe].key=8*(r-1)+c-2;
                queue[qe].depth=depth+1;
                qe++;
                qsize++;
            }
            if(r>=2&&c>=1&&chess[r-2][c-1]==0)
            {
                chess[r-2][c-1]=1;
                queue[qe].key=8*(r-2)+c-1;
                queue[qe].depth=depth+1;
                qe++;
                qsize++;
            }
            if(r>=2&&c<=6&&chess[r-2][c+1]==0)
            {
                chess[r-2][c+1]=1;
                queue[qe].key=8*(r-2)+c+1;
                queue[qe].depth=depth+1;
                qe++;
                qsize++;
            }
            if(r>=1&&c<=5&&chess[r-1][c+2]==0)
            {
                chess[r-1][c+2]=1;
                queue[qe].key=8*(r-1)+c+2;
                queue[qe].depth=depth+1;
                qe++;
                qsize++;
            }
            if(r<=6&&c>=2&&chess[r+1][c-2]==0)
            {
                chess[r+1][c-2]=1;
                queue[qe].key=8*(r+1)+c-2;
                queue[qe].depth=depth+1;
                qe++;
                qsize++;
            }
            if(r<=5&&c>=1&&chess[r+2][c-1]==0)
            {
                chess[r+2][c-1]=1;
                queue[qe].key=8*(r+2)+c-1;
                queue[qe].depth=depth+1;
                qe++;
                qsize++;
            }
            if(r<=5&&c<=6&&chess[r+2][c+1]==0)
            {
                chess[r+2][c+1]=1;
                queue[qe].key=8*(r+2)+c+1;
                queue[qe].depth=depth+1;
                qe++;
                qsize++;
            }
            if(r<=6&&c<=5&&chess[r+1][c+2]==0)
            {
                chess[r+1][c+2]=1;
                queue[qe].key=8*(r+1)+c+2;
                queue[qe].depth=depth+1;
                qe++;
                qsize++;
            }
        }
    }
    return 0;
}

queue数组开65 ac,开64却run time error。
在zoj和hdu开64是ac的,why?

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator