2018焦作区域赛F - Honeycomb

Gym - 102028F
一眼看上去就是一个稍微复杂一点的bfs。
写起来也没遇到太大的障碍,一路顺风顺水写完了。
最后连续wa了三次,检查到头皮发麻也没看出问题。
最后抱着瞎试的心态换掉了setbuf(stdin, NULL);
竟然就a了…

在这里插入图片描述
你说getchar()多好。
关于setbuf(stdin, NULL);为什么不行还不清楚。
还有就是memset()不能乱用,会超时,数组大的话老老实实的for比较好
下面上代码:

#include <bits/stdc++.h>
using namespace std;
/*
1
3 4
  +---+       +---+
 /     \     /     \
+       +---+       +---+
 \           \     /     \
  +   +       +---+   S   +
 /     \     /           /
+       +---+       +   +
 \           \     /     \
  +---+       +---+       +
 /                       /
+       +---+       +   +
 \                 /     \
  +---+       +---+   T   +
       \     /     \     /
        +---+       +---+
*/
/*
1
1 2
  +---+
 /     \
+   S   +---+
 \           \
  +---+   T   +
       \     /
        +---+
*/
char in[4010][6010];
int r,c,starti,startj;
int turn[6][2]={{-2,-6},{-2,6},{-4,0},{4,0},{2,-6},{2,6}};
struct node {
    int x,y,times;
    node(int a,int b,int c) {
        x=a,y=b,times=c;
    }
    node() {}
};
bool judge1(int x,int y) {
    if(x<0||x>=4*r+3)
        return false;
    if(y<0||y>=6*c+3)
        return false;
    if(in[x][y]=='*')
        return false;
    return true;
}
bool judge2(int x,int y) {
    if(in[x][y]=='-'||in[x][y]=='\\'||in[x][y]=='/')
        return false;
    return true;
}
int showMap() {
    for(int i=0;i<4*r+3;i++) {
        printf("%s\n",in[i]);
    }
}
int Search() {
    queue<node> q;
    q.push(node(starti,startj,1));
    in[starti][startj]='*';
    while(!q.empty()) {
        node temp=q.front();
        q.pop();
        if(in[temp.x][temp.y]=='T') {
            return temp.times;
        }
        int x=temp.x,y=temp.y,times=temp.times;
        for(int i=0;i<6;i++) {
            if(judge1(x+turn[i][0],y+turn[i][1])&&judge2(x+turn[i][0]/2,y+turn[i][1]/2)) {
                q.push(node(x+turn[i][0],y+turn[i][1],times+1));
                if(in[x+turn[i][0]][y+turn[i][1]]!='T')
                    in[x+turn[i][0]][y+turn[i][1]]='*';
            }
        }
    }
    return -1;
}
int main() {
    int t;
    while(~scanf("%d",&t)) {
        while(t--) {
            scanf("%d%d",&r,&c);
            //setbuf(stdin, NULL);
            getchar();
            for(int i=0;i<4*r+3;i++) {
                gets(in[i]);
                int len=strlen(in[i]);
                for(int j=0;j<len;j++) {
                    if(in[i][j]=='S') {
                        starti=i,startj=j;
                    }
                }
            }
            printf("%d\n",Search());
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值