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

发一段雷人代码(563ms过)

Posted by Dir at 2009-07-23 17:00:19 on Problem 1915 and last updated at 2009-07-23 17:01:43
#include <stdio.h>
#include <memory.h>
int main()
{
    int tt,m,wide;
    int start[2],end[2];
    int step,i,j,k;
    int map[305][305][2];
    short stp;
    scanf("%d",&tt);
    for(m = 0; m < tt; m ++)
    {     
          step = 0;
          scanf("%d",&wide);
          scanf("%d%d",&start[0],&start[1]);
          scanf("%d%d",&end[0],&end[1]);
          for(i = 0; i < wide + 4; i ++)
          {
                for(j = 0; j < wide + 4; j ++)
                {
                      map[i][j][0] = map[i][j][1] = 0;
                }
          }
          map[start[0] + 2][start[1] + 2][0] = 1;
          k = 0;
          stp = 0;
          while(1)
          {
              for(i = 2; i < wide + 2; i ++)
              {
                    for(j = 2; j < wide + 2; j ++)
                    {
                        if(map[i][j][k] == 1)
                        {
                            if(i == end[0] + 2 && j == end[1] + 2)
                            {
                                 stp = 1;
                                 break;
                            }
                            map[i - 2][j + 1][1 - k] = 1;
                            map[i + 2][j + 1][1 - k] = 1;
                            map[i - 2][j - 1][1 - k] = 1;
                            map[i + 2][j - 1][1 - k] = 1;
                            map[i + 1][j - 2][1 - k] = 1;
                            map[i - 1][j - 2][1 - k] = 1;
                            map[i + 1][j + 2][1 - k] = 1;
                            map[i - 1][j + 2][1 - k] = 1;
                        }
                    }
                    if(stp)
                           break;
              }
              if(stp)
                  break;
              for(i = 2; i < wide + 2; i ++)
              {
                    for(j = 2; j < wide + 2; j ++)
                    {
                          map[i][j][k] = 0;
                    }
              }
              k = 1 - k;
              step ++;                
          }
          printf("%d\n",step);             
    }
    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