一道宽搜模版题,可写错了两个地方的我只得了56(掩面痛哭)

http://10.37.2.111/problem.php?id=1345

先看看正确的

#include <bits/stdc++.h>
#define read read()
#define up(i,l,r) for(int i = l; i<=r; i++)
using namespace std;

int read
{
    ; char ch = getchar();
     || ch > )  ch = getchar();
     && ch <= ) {x =  * x + ch - ; ch = getchar();}
    return x;
}

;

int n,m,k;
int sx,sy,ex,ey;
int ans = INT_MAX;
,,-, ,};//上,下,左,右;
,, ,-,};
struct node{int x,y,step;}st;
int th[N][N],vis[N][N];
int nx,ny;

void updata(int i,int p)
{
    ) (nx += p) > n ?nx = n : nx;     //上
    ) (nx -= p) <  ?nx =  : nx;//下
    ) (ny -= p) <  ?ny =  : ny;//左
    ) (ny += p) > m ?ny = m : ny;//右
}

void bfs()
{
    queue<node>q;
    st.step = ;
    st.x = sx;
    st.y = sy;
    q.push(st);
    vis[sx][sy]=;
    while(!q.empty())
    {
        node cur = q.front(); q.pop();
        );}
        up(i,,)
        {
            nx = cur.x + dx[i];
            ny = cur.y + dy[i];
|| ny <  || nx > n || ny > m || vis[nx][ny]) continue;
            vis[nx][ny] = ;
            node nxt; nxt.x = nx; nxt.y = ny; nxt.step = cur.step + ;
            q.push(nxt);
        }
    }
    printf("Impossible");
}

int main()
{
    freopen("hero2.in","r",stdin);
    n = read; m = read; k = read;
    int x,y;
    ;
    up(i,,k)
    {
        x = read; y = read; th[x][y] = read;
    }
    sx = read; sy = read;
    ex = read; ey = read;
    bfs();
}

错误1:代码笔误;

void updata(int i,int p)
{
    ) (nx += p) > n ?n : nx;     //上
    ) (nx -= p) <  ? : nx;//下
    ) (ny -= p) <  ? : ny;//左
    ) (ny += p) > m ?m : ny;//右
}

看出什么了吗? -> 忘了赋值了;

错误2:思维漏洞;

if(th[nx][ny]) updata(i,th[nx][ny]);

弹簧可以连续跳啊连续跳 -> 所以要多次更新

记住教训啊;

05-11 10:59