今天为了一个制杖问题调了30分钟

今天犯了一个制杖错误(http://ybt.ssoier.cn:8088/)

1330:【例8.3】最少步数

#include <bits/stdc++.h>
using namespace std;
int qx,qy,zx,zy;
queue <int> q;
int x[13]={0,-2,-1,1,2,-2,2,-2,2,-2,-1,1,2},y[13]={0,-2,-2,-2,-2,-1,-1,1,1,2,2,2,2};
bool b[101][101];
int tot[101][101];
int ans[2]={-1,-1},u1,u2;
void gs(){
    while(q.empty() == 0){
        int xx=q.front();
        q.pop();
        int yy=q.front();
        q.pop();
        if(u1==0&&xx == qx && yy == qy)
        {
            u1++;
            ans[0] = tot[qx][qy];
            if(ans[1] != -1)
                return ;
        }
        if(u2 == 0 && xx == zx && yy == zy)
        {
            u2++;
            ans[1] = tot[xx][yy];
            if(ans[0] != -1)
                return ;
        }
        for(int i=1;i<=12;i++){
            int x2=xx+x[i];
            int y2=yy+y[i];
            if(b[x2][y2] == 0 && x2 > 0 && y2 > 0&& x2 <= 100 && y2 <= 100)
            {
                
                tot[x2][y2] = tot[xx][yy] + 1;
                q.push(x2);
                q.push(y2);
                b[x2][y2] == 1;//看到这里了吗,赋值号写成了==,c语言专属毛病.当时都在忙没人给我检查,自己又喜欢赖编辑器
            }
        }
    }
}
int main(){
    scanf("%d%d%d%d",&qx,&qy,&zx,&zy);
    q.push(1);
    q.push(1);
    b[1][1] = 1;
    tot[qx][qy] = 0;
    gs();
    cout<<ans[0]<<endl<<ans[1];
    return 0;
}

传送门

我还当面问一个dalao:你猜会不会执行下一步???,他顿了几秒:你打了两个等号,尴尬死我了;

传送门

小结:遇到玄学的事情不要赖编译器,如果遇到赋值语句不执行看看等号数量

ps:其实改了之后第一次提交CE(轻松编译),原因是调用了windows.h头文件(不是想卡评测机,而是调试)

猜你喜欢

转载自www.cnblogs.com/lztzs/p/10731003.html