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 1000010314 at 2012-04-11 22:03:53 on Problem 2488
#include <cstdio>
#include <cstring>

using namespace std;

const int around[8][2]={{-1,-2},{1,-2},{-2,-1},{2,-1},{-2,1},{2,1},{-1,2},{1,2}};

int data[27][27],m,n,current;
char answer[1352];


bool dfs(int x,int y)
{
    data[x][y]=current++;
    int tmpx=x,tmpy=y;
    for(int i=0;i<8;i++)
    {
        tmpx=x+around[i][0];
        tmpy=y+around[i][1];
        if(tmpx<=m&&tmpx>0&&tmpy<=n&&tmpy>0)
        {
            if(data[tmpx][tmpy]==0)
            {
                if(!dfs(tmpx,tmpy))
                {
                    data[tmpx][tmpy]=0;
                    current--;
                }
            }
        }
    }
    if(current>m*n)
    {
        answer[(data[x][y]<<1)-2]=y+'A'-1;
        answer[(data[x][y]<<1)-1]=x+'0';
        return true;
    }
    return false;
}

int main()
{
    int times;scanf("%d",&times);
    for(int ss=0;ss<times;ss++)
    {
        scanf("%d%d",&m,&n);
        printf("Scenario #%d:\n",ss+1);
        memset(data,0,sizeof(data));
        current=1;
        memset(answer,0,sizeof(answer));
        if(dfs(1,1)){printf("%s\n\n",answer);}
        else{printf("impossible\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