POJ 1957 Beehives 模拟

百度都查不到题解,看了好多关于六边形的博客,还有讲到SLG游戏的,最后干脆直接模拟穷举,AC了

两次WA是因为刚开始判0的时候没加continue...智障了

代码如下:View Source On GitHub

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
struct Point2D
{
    int x,y;
};
int nextvec[6][2]=
{
    {
        1,0
    },
    {
        1,1
    },
    {
        0,1
    },
    {
        -1,0
    },
    {
        -1,-1
    },
    {
        0,-1
    }
};

char stra[1024];
char strb[1024];
char buff[1024];
Point2D pa[2000];
Point2D pb[2000];

bool cmp(const Point2D& a,const Point2D& b)
{
    if(a.x==b.x)
    {
        return a.y < b.y;
    }
    return a.x < b.x;
}

int main()
{
    int N;
    scanf("%d%*c",&N);
    while(N--)
    {
        memset(pa,0,sizeof(pa));
        memset(pb,0,sizeof(pb));
        gets(stra);
        gets(strb);
        gets(buff);
        int lena=strlen(stra);
        int lenb=strlen(strb);
        if(lena==0&&lenb==0)
        {
            printf("true\n");
            continue;
        }
        else if(lena!=lenb)
        {
            printf("false\n");
            continue;
        }
        int x=0;
        int y=0;
        for(int i=0;i<lena;i++)
        {
            int dir=(stra[i]-'a');
            x+=nextvec[dir][0];
            y+=nextvec[dir][1];
            pa[i].x=x;
            pa[i].y=y;
        }
        pa[lena].x=0;
        pa[lena].y=0;
        sort(pa,pa+lena+1,cmp);

        int flag=0;
        for(int dirCLT=0;dirCLT<6;dirCLT++)
        {
            for(int startID=0;startID<=lena;startID++)
            {
                x=pa[startID].x;
                y=pa[startID].y;
                for(int i=0;i<lenb;i++)
                {
                    int dir=(strb[i]-'a'+dirCLT)%6;
                    x+=nextvec[dir][0];
                    y+=nextvec[dir][1];
                    pb[i].x=x;
                    pb[i].y=y;
                }
                pb[lenb].x=pa[startID].x;
                pb[lenb].y=pa[startID].y;
                sort(pb,pb+lenb+1,cmp);
                int tflag=0;
                for(int i=0;i<=lena;i++)
                {
                    if(pa[i].x!=pb[i].x||pa[i].y!=pb[i].y)
                    {
                        tflag=1;
                        break;
                    }
                }
                if(tflag==0)
                {
                    flag=1;
                    break;
                }
            }
            if(flag)
                break;
        }
        if(flag)
        {
            printf("true\n");
        }
        else
        {
            printf("false\n");
        }
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值