加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

POJ PKU 2632 模拟

(2010-02-28 20:16:00)
标签:

杂谈

分类: 杂题

MyPojId == zhaozhouyang

模拟题,注意方向数字化,转向时对4取模就好了。

还有想知道一下向这种题目的输入 数字 数字 字母 的形式有什么简便的方法吗?

由于中间有空格,我把字母当做字符串处理了。

#include<iostream>
#include<string>
using namespace std;
struct robot
{
    int we, ns, ori;//ori : 0 N 1 E 2 S 3 W
}ro[101];
string str;
int move[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int ori[200], vst[101][101];
int main()
{
    int k;
    ori['N'] = 0, ori['E'] = 1, ori['S'] = 2, ori['W'] = 3;
    ori['L'] = 3, ori['R'] = 1;
    scanf("%d", &k);
    while(k--)
    {
        int a, b, n, m, id, repet, act, temp;
        memset(vst, 0, sizeof(vst));
        scanf("%d%d%d%d", &a, &b, &n, &m);
        for(int i = 1; i <= n; i )
        {
            cin >> ro[i].we >> ro[i].ns >> str;
            ro[i].ori = ori[str[0]];
            vst[ro[i].we][ro[i].ns] = i;
        }
        int state = 0, ans1, ans2;
        while(m--)
        {
            cin >> id >> str >> repet;
            if (str[0] != 'F')
            {
                repet %= 4;
                ro[id].ori = (ro[id].ori repet * ori[str[0]]) % 4;
            }
            else
            {
                while(!state && repet--)
                {
                    vst[ro[id].we][ro[id].ns] = 0;
                    ro[id].we = move[ro[id].ori][0];
                    ro[id].ns = move[ro[id].ori][1];
                    if (ro[id].we == 0 || ro[id].we == a 1 || ro[id].ns == 0 || ro[id].ns == b 1)
                        state = 1, ans1 = id;
                    else if (vst[ro[id].we][ro[id].ns])
                        state = 2, ans1 = id, ans2 = vst[ro[id].we][ro[id].ns];
                    else
                        vst[ro[id].we][ro[id].ns] = id;
                }
            }
        }
        if (!state)
            printf("OK\n");
        else if (state == 1)
            printf("Robot %d crashes into the wall\n", ans1);
        else
            printf("Robot %d crashes into robot %d\n", ans1, ans2);
    }
    return 0;
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有