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 xinghun4 at 2007-09-06 20:47:22 on Problem 2632
In Reply To:牛人们帮我看看 Posted by:xinghun4 at 2007-09-06 20:29:29
> #include<stdio.h>
> typedef struct n
> {  int x,y;
>    char c;
> }ROBOT;
> ROBOT robot[101];
> 
> typedef struct m
> {  int num,repeat;
>    char le;
> }INS;
> INS dir[101];
> 
> int n,a,b,crash;
> int judge(int i)
> {  int j;
>     if(robot[i].x<1||robot[i].x>=a+1||robot[i].y<1||robot[i].y>=b+1)
>        return 1;
>     for(j=1;j<=n;j++)
>      if(j!=i&&robot[i].x==robot[j].x&&robot[i].y==robot[j].y)
>      {  crash=j;
>         return 2;
>      }
>    return 0;
> }
> int move(int j)
> {  int xx,yy,t;
>    int k=dir[j].num;
>    char d=dir[j].le;
>    if(d=='R')
>    {   if(robot[k].c=='N') robot[k].c='E';
>        if(robot[k].c=='S') robot[k].c='W';
>        if(robot[k].c=='W') robot[k].c='N';
>        if(robot[k].c=='E') robot[k].c='S';
>    }
>    if(d=='L')
>     {  if(robot[k].c=='N') robot[k].c='W';
>        if(robot[k].c=='S') robot[k].c='E';
>        if(robot[k].c=='W') robot[k].c='S';
>        if(robot[k].c=='E') robot[k].c='N';
>    }
>    if(d=='F')
>     {  if(robot[k].c=='N') {xx=0;yy=1;}
>        if(robot[k].c=='S') {xx=0;yy=-1;}
>        if(robot[k].c=='W') {xx=-1;yy=0;}
>        if(robot[k].c=='E') {xx=1;yy=0;}
>        robot[k].x+=xx;
>        robot[k].y+=yy;
>        t=judge(k);
>        if(t==1)
>        {  printf("Robot %d crashes into the wall\n",k);
>           return 1;
>        }
>        if(t==2)
>        {  printf("Robot %d crashes into robot %d\n",k,crash);
>           return 1;
>        }
>    }
>    return 0;
> }
> int main()
> {
>     int m,k,i,j,flag,h;
>     scanf("%d",&k);
>     while(k--)
>     {  scanf("%d %d %d %d",&a,&b,&n,&m);
>        for(i=1;i<=n;i++)
>           scanf("%d %d %c",&robot[i].x,&robot[i].y,&robot[i].c);
>        for(i=1;i<=m;i++)
>           scanf("%d %c %d",&dir[i].num,&dir[i].le,&dir[i].repeat);
>        for(flag=1,i=1;i<=m&&flag;i++)
>        {  if(dir[i].le=='L'||dir[i].le=='R')
>               dir[i].repeat%=4;
>           for(j=1;j<=dir[i].repeat&&flag;j++)
>           { h=move(i);
>             if(h) flag=0;
>           }
>        }
>        if(flag) printf("OK\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