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

为什么是runtime error,哪位帮我看看啊!拜托了!~

Posted by httplxting at 2010-08-09 11:31:24 on Problem 2488
#include<stdio.h>
int direction[8][2]={{-1,-2},{1,-2},{-2,-1},{2,-1},{-2,1},{2,1},{-1,2},{1,2}};
int map[28][28];
int position[1000];
int flag,step;
int p,q;
void run(int x,int y)
{
    int k;
    int newx,newy;
    position[++step]=x*26+y;
    map[x][y]=1;
    if(step==p*q-1)
    {
         flag=1;return;          
    }
    for(k=0;k<8;k++)
    {
          newx=x+direction[k][0];
          newy=y+direction[k][1];
          if(newx>=0&&newx<p&&newy>=0&&newy<q&&map[newx][newy]==0)
          {
                run(newx,newy); 
                map[newx][newy]=0; 
          }
    }
}
int main()
{
    int n;
    int r,s;
    scanf("%d",&n);
    for(s=0;s<n;s++)
    {
         flag=0;
         step=-1;
         scanf("%d%d",&p,&q);
         run(0,0);
         printf("Senario#%d:\n",s+1);  
         if(flag==0)
         printf("imposible\n\n");
         if(flag==1)
         {
                    for(r=0;r<p*q;r++)
                    {
                         printf("%c%d",position[r]%26+'A',position[r]/26+1);
                                      
                    }
                    printf("\n\n");
         }
                  
    }
return 0;
}

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