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 zhangxiao1124 at 2008-02-29 23:02:15 on Problem 2618
WA郁闷了



#include<iostream>
using namespace std;

#define maxn 20
#define maxl 20
#define maxq 1000

int X,Y,A,B,C,D;
bool obs[10][maxn][maxn],done[maxn][maxn][10];
struct node{int x,y,f,s;};
node q[maxq];

inline int change(int face,int move)
{
    if (face==1) {if (move==1) return 5;else if (move==2) return 3;else if (move==3) return 2;else return 4;} 
    else if (face==2) {if (move==1) return 1;else if (move==3) return 6;else return 2;}
    else if (face==3) {if (move==2) return 6;else if (move==4) return 1;else return 3;}
    else if (face==4) {if (move==2) return 1;else if (move==4) return 6;else return 4;}
    else if (face==5) {if (move==1) return 6;else if (move==3) return 1;else return 5;}
    else {if (move==1) return 2;else if (move==2) return 4;else if (move==3) return 5;else return 3;}
}

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int x,y,f,head,tail,now;
    char str[maxl];
    scanf("%d%d%d%d%d%d",&X,&Y,&A,&B,&C,&D);
    scanf("\n");
    memset(obs,0,sizeof obs);
    while (scanf("%s",&str)!=EOF)
    {
          if (str[0]=='v') now=0;
          else if (str[0]=='h') now=1;
          else {
               x=atoi(str); scanf("%d",&y);
               obs[now][x][y]=true;
          }
    }
    head=0; tail=1; 
    q[1].x=A; q[1].y=B; q[1].f=1; q[1].s=0;
    memset(done,0,sizeof(done)); done[A][B][1]=true;
    while (head<tail)
    {
          head++; x=q[head].x; y=q[head].y; f=q[head].f;
          if (x>1 && !obs[0][x-1][y] && !done[x-1][y][change(f,1)])
          {
                  tail++; done[x-1][y][change(f,1)]=true;
                  q[tail].x=x-1; q[tail].y=y; q[tail].f=change(f,1); q[tail].s=q[head].s+1;
                  if (q[tail].x==C && q[tail].y==D && q[tail].f==1) { printf("%d\n",q[tail].s); return 0;}                
          }
          if (x<X && !obs[0][x][y] && !done[x+1][y][change(f,3)])
          {
                  tail++; done[x+1][y][change(f,3)]=true;
                  q[tail].x=x+1; q[tail].y=y; q[tail].f=change(f,3); q[tail].s=q[head].s+1;
                  if (q[tail].x==C && q[tail].y==D && q[tail].f==1) { printf("%d\n",q[tail].s); return 0;}                
          }
          if (y>1 && !obs[1][x][y-1] && !done[x][y-1][change(f,4)])
          {
                  tail++; done[x][y-1][change(f,3)]=true;
                  q[tail].x=x; q[tail].y=y-1; q[tail].f=change(f,4); q[tail].s=q[head].s+1;
                  if (q[tail].x==C && q[tail].y==D && q[tail].f==1) { printf("%d\n",q[tail].s); return 0;}                
          }
          if (y<Y && !obs[1][x][y] && !done[x][y+1][change(f,2)])
          {
                  tail++; done[x][y+1][change(f,2)]=true;
                  q[tail].x=x; q[tail].y=y+1; q[tail].f=change(f,2); q[tail].s=q[head].s+1;
                  if (q[tail].x==C && q[tail].y==D && q[tail].f==1) { printf("%d\n",q[tail].s); return 0;}                
          }
    }
    printf("%s\n","no");
    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