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 q847087628 at 2016-04-03 20:48:53 on Problem 2632 and last updated at 2016-04-03 20:52:01
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXM 105
struct robot
{
    int x, y;
    char pos;
}a[MAXM];
struct point
{
    int s, t;
}ans[5];
char s[2];
int p, q, n, m;
int map[MAXM][MAXM], res, flag[MAXM];
char s1[150], s2[150];
void rotate(int aim, char act, int repeat)
{
    int i;
    
    for(i = 1; i <= repeat; i++)
    {
        if(act == 'L')
            a[aim].pos = s1[a[aim].pos];
        else
            a[aim].pos = s2[a[aim].pos];
    }
    return;
}
void walk(int aim, int x, int y, int repeat)
{
    if(x > n || x < 1 || y > m || y < 1)
    {
        ans[res].s = aim;
        ans[res++].t = 0;
        flag[aim] = 1;
        return;
    }
    else if(map[x][y] != 0 && flag[map[x][y]] == 0 && map[x][y] != aim)
    {
        ans[res].s = aim;
        ans[res++].t = map[x][y];
        flag[aim] = 1;
        flag[map[x][y]] = 1;
        return;
    }
    else if(repeat == 0)
    {
        map[x][y] = aim;
        a[aim].x = x;
        a[aim].y = y;
        return;
    }
    else
    {
        if(a[aim].pos == 'E')
            walk(aim, x, y+1, repeat-1);
        else if(a[aim].pos == 'W')
            walk(aim, x, y-1, repeat-1);
        else if(a[aim].pos == 'N')
            walk(aim, x-1, y, repeat-1);
        else
            walk(aim, x+1, y, repeat-1);
    }
    return;
}
void position(int aim, char act, int repeat)
{
    if(act == 'L' || act == 'R')
    {
        repeat %= 4;
        rotate(aim, act, repeat);
    }
    else
    {
        map[a[aim].x][a[aim].y] = 0;
        walk(aim, a[aim].x, a[aim].y, repeat);
    }
    return;
}
void init()
{
    s1['E'] = 'N';
    s1['N'] = 'W';
    s1['W'] = 'S';
    s1['S'] = 'E';
    s2['E'] = 'S';
    s2['S'] = 'W';
    s2['W'] = 'N';
    s2['N'] = 'E';
}
void prit()
{
    if(ans[0].t == 0)
        printf("Robot %d crashes into the wall\n", ans[0].s);
    else
        printf("Robot %d crashes into robot %d\n", ans[0].s, ans[0].t);
}
int main()
{
    int t;
    
    cin >> t;
    while(t--)
    {
        int i;
        int aim, count;
        
        cin >> m >> n;
        cin >> p >> q;
        memset(map, 0, sizeof(map));
        for(i = 1; i <= p; i++)
        {
            cin >> a[i].y >> a[i].x >> s;
            a[i].pos = s[0];
            a[i].x = n-a[i].x+1;
            map[a[i].x][a[i].y] = i;
        }
        init();
        res = 0;
        memset(flag, 0, sizeof(flag));
        for(i = 1; i <= q; i++)
        {
            cin >> aim >> s >> count;
            if(res == 0)
                position(aim, s[0], count);
        }
        if(res == 0)
            cout << "OK" << endl;
        else
            prit();
    }
    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