1 条题解

  • 0
    @ 2025-10-8 16:54:35
    #include<cstdio>
    using namespace std;
    int max(int x, int y){return x>y?x:y;}
    int min(int x, int y){return x<y?x:y;}
    struct point
    {
        int x, y;
    }p[4];int maxx=1, minx=0, maxy=1, miny=0, t=0;
    char c[5];
    int main()
    {
        p[0]=(point){0, 1};//左前 
        p[1]=(point){1, 1};//右前 
        p[2]=(point){0, 0};//左后 
        p[3]=(point){1, 0};//右后 
        int T;scanf("%d", &T);
        while(T--)
        {
            scanf("%s", c);
            int q=(c[0]=='F'?0:2)+(c[1]=='L'?0:1);
            c[2]=(c[2]=='F'?0:c[2]=='R'?1:c[2]=='B'?2:c[2]=='L'?3:4);
            if(c[2]<4)c[2]=(c[2]+t)%4;
                 if(c[2]==0)
            {
                p[q].y++;maxy=max(maxy, p[q].y);
            }
            else if(c[2]==1)
            {
                p[q].x++;maxx=max(maxx, p[q].x);
            }
            else if(c[2]==2)
            {
                p[q].y--;miny=min(miny, p[q].y);
            }
            else if(c[2]==3)
            {
                p[q].x--;minx=min(minx, p[q].x);
            }
            else if(c[2]==4)
            {
                for(int i=0;i<4;i++)
                {
                    p[i]=(point){p[q].x+p[i].y-p[q].y, p[q].y-p[i].x+p[q].x};
                    maxx=max(maxx, p[i].x);
                    minx=min(minx, p[i].x);
                    maxy=max(maxy, p[i].y);
                    miny=min(miny, p[i].y);
                }
                t++;
            }
            int s=0;
            for(int i=0;i<4;i++)if(p[i].x==p[q].x&&p[i].y==p[q].y)s++;
            if(s>1){puts("-1");return 0;}
        }
        printf("%d\n", (maxx-minx+1)*(maxy-miny+1));
        return 0;
    }
    
    • 1

    *【模拟(难度:8)】奶牛芭蕾(未解决)

    信息

    ID
    879
    时间
    1000ms
    内存
    128MiB
    难度
    7
    标签
    递交数
    14
    已通过
    11
    上传者