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

Re:高手帮忙看看,到底哪里错了?为什么样例都过了,题还没过

Posted by qingqingdilai at 2011-03-31 22:19:58 on Problem 2488
In Reply To:高手帮忙看看,到底哪里错了?为什么样例都过了,题还没过 Posted by:1004091222 at 2011-03-14 20:56:22
> #include<iostream>
> #include<cstdio>
> #include<cstring>
> using namespace std;
> 
> int p,q;
> int visit[30][30];
> int dy[8] = {-2, -2, -1, -1, 1, 1, 2, 2};
> int dx[8] = {-1, 1, -2, 2, -2, 2, -1, 1};
> char step[60];
> 
> int dfs(int x,int y,int k)
> {
>     
>     if(k==q*p)
>     {
>         return 1;
>     }
>     for(int i=0;i<8;i++)
>     {
>         int x1=x+dx[i];
>         int y1=y+dy[i];
>               if(x1>=0&&x1<q&&y1>=0&&y1<p&&visit[y1][x1]==0)
>         {
>             visit[y1][x1]=1;
>             step[(k<<1)]=x1+'A';
>             step[(k<<1)+1]=y1+'1';
>             if(dfs(x1,y1,k+1))
>             {
> 
>                 return 1;
>             }
>             visit[y1][x1]=0;
>         }
>       }
>     return 0;
> 
> 
> 
> }
> 
> int main()
> {
>     int t;
>     scanf("%d",&t);
>     int h=1;
>     while(t--)
>     {
>         scanf("%d%d",&p,&q);
>         memset(visit,0,sizeof(visit));
>         memset(step,0,sizeof(step));
>         step[0]='A';
>         step[1]='1';
>         visit[0][0]=1;
>         if(dfs(0,0,1))
>         {
>             int b=strlen(step);
>             step[b]='\0';
>             printf("Scenario #%d:\n",h++);
>             printf("%s\n\n",step);
>         }
>         else
>         {
>             printf("Scenario #%d:\n",h++);
>             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