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

为什么我在新版poj提交就wa了,可是在旧版提交就直接过了呢

Posted by kobe6672823 at 2010-05-01 13:34:49 on Problem 2488
代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct {int r; char c;}point;
int visit[50][50];
int dirr[50] = {-1, 1, -2, 2, -2, 2, -1, 1};
int dirc[50] = {-2, -2, -1, -1, 1, 1, 2, 2};
int find, step;
point path[2500];
int p, q;
void dfs(int i, int j);
int main()
{
    int n, t = 0, midp, i, j;
    scanf("%d", &n);
    memset(visit, 0, sizeof (visit));
    while (n--)
    {
        t++;
        find = 0;
        scanf("%d%d", &p, &q);
        printf("Scenario #%d:\n", t);
        /*if (p % 2 == 0)
        {
            midp = p / 2;
        }
        else
        {
            midp = p / 2 + 1;
        }*/
        for (j=1; j<=q; j++)
        {
            for (i=1; i<=p; i++)
            {
                step = 1;
                path[step].r = i;
                path[step].c = j + 'A' - 1;
                visit[i][j] = 1;
                dfs(i, j);
                visit[i][j] = 0;
                if (find)
                {
                    break;
                }
            }
            if (find)
            {
                break;
            }
        }
        if (find == 0)
        {
            printf("impossible");
        }
        printf("\n\n");
    }
    system("pause");
    return 0;
}

void dfs(int i, int j)
{
     int r, c, count;
     if (find == 0)
     {
         if (step == p * q)
         {
             find = 1;
             for (count=1; count<=step; count++)
             {
                 printf("%c%d", path[count].c, path[count].r);
             }
         }
         else if (step != p * q)
         {
             for (count=0; count<=7; count++)
             {
                 r = i + dirr[count];
                 c = j + dirc[count];
                 if (r >= 1 && r <= p && c >= 1 && c <= q && visit[r][c] == 0)
                 {
                     step++;
                     path[step].r = r;
                     path[step].c = c + 'A' - 1;
                     visit[r][c] = 1;
                     dfs(r, c);
                     step--;
                     visit[r][c] = 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