jQuery火箭图标返回顶部代码 - 站长素材
jQuery火箭图标返回顶部代码 - 站长素材

洛谷p1747好奇怪的游戏题解

题目

永远不要怀疑劳动人民的智慧!

把快读里最后的return直接返回零的

我已经不是第一次写错了!

我要是再写错我就******

主要是逆向思维,把从两个点往(1, 1)走想成从(1, 1)点往这两个点走就好了

没有什么的

#include <cstdio>
#include <iostream>
using namespace std;
const int N = 25;
int ax, ay, bx, by, ans[N][N], head, tail, x, y;
int dx[12] = {-2, -2, -2, -2, -1, -1, 1, 1, 2, 2, 2, 2}, dy[12] = {-2, -1, 1, 2, -2, 2, -2, 2, -2, -1, 1, 2};
bool vis[N][N];
struct node{
    int x, y;
}zhan[N << 2];
int read() {
    int s = 0, w = 1;
    char ch = getchar();
    while(!isdigit(ch)) {if(ch == '-') w = -1;ch = getchar();}
    while(isdigit(ch)) {s = s * 10 + ch - '0';ch = getchar();}
    return s * w;
}
void bfs(int ax, int ay, int bx, int by) {
    zhan[1].x = 1;
    zhan[1].y = 1;
    tail = 1;
    ans[1][1] = 1;
    vis[1][1] = 1;
    while(head < tail) {
        head++;
        for(int i = 0; i < 12; i++) {
            x = zhan[head].x + dx[i], y = zhan[head].y + dy[i];
            if(x >= 1 && x <= 20 && y >= 1 && y <= 20 && !vis[x][y]) {
                zhan[++tail].x = x;
                zhan[tail].y = y;
                ans[x][y] = ans[zhan[head].x][zhan[head].y] + 1;
                vis[x][y] = 1;
            }
        }
    }
}
int main() {
    ax = read(), ay = read();
    bx = read(), by = read();
    bfs(ax, ay, bx, by);
    printf("%d\n%d\n", ans[ax][ay] - 1, ans[bx][by] - 1);
    return 0;
}

谢谢收看,祝身体健康!

posted @ 2019-10-16 17:05  lzpclxf  阅读(185)  评论(0编辑  收藏  举报