“kuangbin带你飞”专题计划——专题二:搜索进阶

"kuangbin带飞"

 

1.HDU-1043-Eight:啥?康拓双映射,啥????

代码(待修改——几乎没啥进展):

#include <string.h>

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

// #define int long long
#define pb push_back
#define mst(a, i) memset(a, i, sizeof(a))
#define dbg(x) cout << #x << "===" << x << endl
#define ed(x, y) ((x)*3 + (y))
using namespace std;
void read(int &x) {
    int res = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
        res = (res << 3) + (res << 1) + (c - '0'), c = getchar();
    x = f * res;
}
void OUT(int x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) OUT(x / 10);
    putchar(x % 10 + '0');
}
void print(int a, char c) { OUT(a), putchar(c); }

const int maxn = 2e2 + 10;
const int mod = 1e9 + 7;

int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
char mc[] = "durl", c;
int vis[10], sx, sy;
bool f1, f2,f;
bool ok(int x, int y) {
    if (x >= 0 && x < 3 && y >= 0 && y < 3) return true;
    return false;
}
void dfs(int *vis, int k, int x, int y) {
    f=true;
    for(int i=0;i<9;i++) if(vis[i]!=i+1) f=false;
    if(f){
        return ;
    }
    // f1 = true, f2 = true;
    // for (int i = 0; i < 3; i++)
        // if (vis[i] != i + 1) f1 = false;
    // for (int i = 3; i < 6; i++)
        // if (vis[i] != i + 1) f2 = false;
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (ok(nx, ny)) {
            swap(vis[ed(nx, ny)], vis[ed(x, y)]);
            dfs(vis, k + 1, nx, ny);
            swap(vis[ed(nx, ny)], vis[ed(x, y)]);
        }
    }
}
signed main() {
    mst(vis, -1);
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c;
            int tmp;
            if (c >= '0' && c <= '9')
                tmp = c - '0';
            else
                tmp = 9, sx = i, sy = j;  // x->9
            vis[ed(i, j)] = tmp;
        }
    }
    dfs(vis, 0, sx, sy);
    // print(ans,'\n');
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值