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

写的这么长,以为又是WA的节奏 , 竟然一次就AC了,贴代码!

Posted by windthenrain at 2015-02-25 17:53:35 on Problem 2632
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;
struct robot
{
    int x , y ;
    int dir ;
}a[200];

struct instruction
{
    int num ;
    char act ;
    int rep ;
}ins[200];

int EW , NS ;
int n , m ;
bool flag ;
int map[150][150];

void crash (int No)
{
    int k = ins[No].rep ;
    int t = ins[No].num ;
    map[a[t].x][a[t].y] = 0 ;
    switch (a[t].dir)
    {
        case 0 :
                for (int i = 0 ; i < k && a[t].x && a[t].y ; i++)
                    if (map[a[t].x][++a[t].y]) {
                            flag = 1 ;
                            printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
                            break ;
                        }
                    break ;
        case 1 :
                for (int i = 0 ; i < k && a[t].x && a[t].y ; i++)
                    if (map[++a[t].x][a[t].y]) {
                            flag = 1 ;
                            printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
                            break ;
                        }
                    break ;
        case 2 :
                for (int i = 0 ; i < k && a[t].x && a[t].y ; i++)
                    if (map[a[t].x][--a[t].y]) {
                            flag = 1 ;
                            printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
                            break ;
                        }
                    break ;
        case 3 :
                for (int i = 0 ; i < k && a[t].x && a[t].y; i++)
                    if (map[--a[t].x][a[t].y]) {
                            flag = 1 ;
                            printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
                            break ;
                        }
                        break ;
    }
     map[a[t].x][a[t].y] = t ;
    if (a[t].x == 0 || a[t].x >= EW + 1 || a[t].y == 0 || a[t].y >= NS + 1) {
        printf ("Robot %d crashes into the wall\n" , t) ;
        flag = 1 ;
    }
}
void solve (int No)
{
    int k = ins[No].num ;
    switch (ins[No].act)
    {
        case 'L' : a[k].dir -= ins[No].rep ; a[k].dir %= 4 ; a[k].dir += 4 ; a[k].dir %= 4 ; break ;
        case 'R' : a[k].dir += ins[No].rep ; a[k].dir %= 4 ; a[k].dir += 4 ; a[k].dir %= 4 ; break ;
        case 'F' :  crash (No) ;
    }
}
int main ()
{
   // freopen ("a.txt" , "r" , stdin) ;
    int T ;
    scanf ("%d" , &T) ;
    char temp ;
    while (T--) {
        memset (map , 0 , sizeof(map) ) ;
        scanf ("%d%d" , &EW , &NS) ;
        scanf ("%d%d" , &n , &m) ;
        for (int i = 1 ; i <= n ; i++) {
            cin >> a[i].x >> a[i].y >> temp ;
         //   cout << temp <<endl ;
            map[a[i].x][a[i].y] = i ;
            switch (temp)
            {
                case 'E' : a[i].dir = 1 ; break ;
                case 'S' : a[i].dir = 2 ; break ;
                case 'W' : a[i].dir = 3 ; break ;
                case 'N' : a[i].dir = 0 ; break ;
            }
        //    printf ("a[%d].dir=%d\n" , i , a[i].dir) ;
        }
        for (int i = 0 ; i < m ; i++)
            cin >> ins[i].num >> ins[i].act >> ins[i].rep ;

        flag = 0 ;
    //    printf ("a[1].dir=%d\n" , a[1].dir) ;
        for (int i = 0 ; i < m ; i++) {
          /*  for (int i = 1 ; i <= EW ; i++) {
                for (int j = 1 ; j <= NS ; j++) {
                    printf ("%d " , map[i][j]) ;
                }
                puts("");
            }
            puts ("") ;*/
            solve (i) ;
          /*  for (int i = 1 ; i <= EW ; i++) {
                for (int j = 1 ; j <= NS ; j++) {
                    printf ("%d " , map[i][j]) ;
                }
                puts("");
            }
            printf ("\n\n\n") ; */
            if (flag)
                break ;
        }

        if (!flag)
            puts ("OK") ;
    }
    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