奶牛芭蕾

#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_map>

#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

PII p[4] = {{0, 1}, {1, 1}, {0, 0}, {1, 0}};
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
unordered_map<string, int> id = {{"FL", 0}, {"FR", 1}, {"RL", 2}, {"RR", 3}};
unordered_map<char, int> turn = {{'F', 0}, {'B', 2}, {'L', 3}, {'R', 1}};

void rotate(PII& a, PII& b)
{
    b.x -= a.x, b.y -= a.y;
    int x = b.y, y = -b.x;
    b.x = a.x + x, b.y = a.y + y;
}

int main()
{
    int n;
    cin >> n;

    int minx = 0, maxx = 1, miny = 0, maxy = 1;

    int d = 0;
    while (n -- )
    {
        string str;
        cin >> str;
        int k = id[str.substr(0, 2)];
        char c = str[2];
        if (c != 'P')
        {
            int t = (d + turn[c]) % 4;
            p[k].x += dx[t], p[k].y += dy[t];
        }
        else
        {
            for (int i = 0; i < 4; i ++ )
                if (i != k)
                    rotate(p[k], p[i]);
            d = (d + 1) % 4;
        }

        for (int i = 0; i < 4; i ++ )
            for (int j = 0; j < i; j ++ )
                if (p[i] == p[j])
                {
                    puts("-1");
                    return 0;
                }

        for (int i = 0; i < 4; i ++ )
        {
            minx = min(minx, p[i].x);
            miny = min(miny, p[i].y);
            maxx = max(maxx, p[i].x);
            maxy = max(maxy, p[i].y);
        }
    }

    cout << (maxx - minx + 1) * (maxy - miny + 1) << endl;
    return 0;
}
全部评论

相关推荐

11-24 19:04
已编辑
湖南工商大学 Java
点赞 评论 收藏
分享
11-30 11:07
河南大学 Java
宇宙厂 测开 n*15
丘丘给个offer:有后选后
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务