hdu1043八数码 bfs 打表/双向bfs/A*+康托判重+逆序奇偶剪枝

HDU 1043(八数码问题) 一道八数码的题目,这里介绍其中一个解法:哈希+打表(比较水但简单的解法)。        首先,题目解法是将9个数字('x'看成数字9)的每一种排列看成一种状态,则共有9!种不同的状态。我们从结果状态(1,2,3,4,5,6,7,8,9,)开始bfs搜索,每到达一个状态就将这个状态标记上(一是标记这个状态可以到达结果,二是标记访问了这个状态,防止重复访问,ps:利用一个flag数组来进行标记), 阅读详情

写之前拜读了这篇文章:八数码的八境界

个人觉得写顺序为

一(可写可不写,介意找工作的的人最好试试这种写法)-->三 -->二 -->四 -> 六-->八

境界一、逆向广搜+STL

多组输入输出,可以想到打表,bfs时间复杂度为9!,查询复杂度为O(1)

判重方法:

set<node>vis;
set红黑树实现,查找效率log(n);总的效率nlog(n)(10^6),肯定会TLE

#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
using namespace std;

struct node{
public:
    node(string s, string pa, int p):sty(s),path(pa),pos(p){}
public:
    string sty;
    string path;
    int pos;
};
map<string,string>res;
set<string>vis;
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
string dir("durl");//ÄæÏòËÑË÷

bool check(int x,int y)
{
    if(x<0||x>2||y<0||y>2)return false;
    else return true;
}

void bfs(){
    queue<node>q;
    node n("12345678x","",8);
    vis.insert("12345678x");
    q.push(n);
    while(!q.empty()){
        n=q.front();
        q.pop();
        int x=n.pos/3;
        int y=n.pos%3;
        for(int i=0;i<4;++i){
            int newx=x+dx[i];
            int newy=y+dy[i];
            if(!check(newx,newy))continue;
            int newpos=newx*3+newy;
            swap(n.sty[n.pos],n.sty[newpos]);
            if(vis.find(n.sty)!=vis.end()){
                swap(n.sty[n.pos],n.sty[newpos]);
                continue;
            }
            else{
                q.push(node(n.sty,dir[i]+n.path,newpos));
                vis.insert(n.sty);
                res[n.sty]=dir[i]+n.path;
                swap(n.sty[n.pos],n.sty[newpos]);
            }
        }
    }

}

int main()
{
    //freopen("in.txt","r",stdin);
    string in;
    string tmp;
    int spos;
    res[in]="";
    bfs();
    while(cin>>tmp){
        in.push_back(tmp[0]);
        for(int i=1;i<9;++i){
            cin>>tmp;
            in.push_back(tmp[0]);
        }
        //cout<<in<<endl;
        if(res[in]=="")printf("unsolvable\n");
        else cout<<res[in]<<endl;
    }

    return 0;
}


这份代码由于将path放在node里面,也会MLE

境界三、逆向广搜+哈希+打表

     是对境界一的改进,set判重改进为cantor判重

     从目标状态123456780反向搜索,记录所有可达状态的路径

     用了两种记录路径的方法,一种是用char path[maxn][36],每个节点维护一个len变量;第二种是每个状态记录上一个状态parent,

path[cur.status].from=parent.stauts
上面是第二种方法,下面是第一种方法

代码如下

//char path[maxn][42]

#include <iostream>
#include <cstdio>
#include <memory.h>
#include <queue>
#include <string>
#include <cstring>

using namespace std;
const int maxn = 362880 + 5;
int fac[9];
char path[maxn][42];
int vis[maxn];

int dx[] = { -1, 1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };
char dir[]="durl";

struct node
{
public:
    node(int p, int s, int l) :pos(p), status(s), len(l){}
public:
    int pos;
    int status;
    int len;
};

void calFac(int *f, int n)
{
    f[0] = 1;
    for (int i = 1; i<n; ++i)f[i] = f[i - 1] * i;
}
int encodeCantor(int *s)
{
    int i, j, num, temp;
    num = 0;
    for (i = 0; i<9; ++i){
        temp = 0;
        for (j = i + 1; j<9; ++j){
            if (s[j]<s[i])
                temp++;
        }
        num += fac[9 - 1 - i] * temp;
    }
    return num;
}

void decodeCantor(int *s, int val)
{
    bool flag[10];
    memset(flag, 0, sizeof(flag));
    for (int i = 0; i<9; ++i){
        int _rank = val / fac[8 - i];
        for (int j = 0; j <= _rank; ++j){
            if (flag[j]){
                _rank++;
            }
        }
        s[i] = _rank;
        flag[_rank] = true;;
        val = val%fac[8 - i];
    }
}

bool check(int x, int y)
{
    if (x<0 || y<0 || x>2 || y>2)return false;
    else return true;
}

void bfs()
{
    queue<node>q;
    int s[] = { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
    node n(8, encodeCantor(s),0);
    vis[n.status] = 1;
    path[n.status][0] = '\0';
    q.push(n);
    while (!q.empty()){
        n = q.front();
        q.pop();
        int x = n.pos / 3; int y = n.pos % 3;
        for (int i = 0; i<4; ++i){
            int newx = x + dx[i];
            int newy = y + dy[i];
            if (!check(newx, newy))continue;
            int newpos = newx * 3 + newy;
            decodeCantor(s, n.status);
            swap(s[n.pos], s[newpos]);
            int nstatus = encodeCantor(s);
            if (!vis[nstatus]){
                for (int i = 0; i < n.len; i++)path[nstatus][i] = path[n.status][i];
                path[nstatus][n.len] = dir[i];
                path[nstatus][n.len+1] = '\0';
                vis[nstatus] = 1;
                q.push(node(newpos, nstatus,n.len+1));
            }
            swap(s[n.pos], s[newpos]);
        }

    }

}

void init()
{
    calFac(fac, 9);
    memset(vis, 0, sizeof(vis));
    //cout<<fac[8]*9<<endl;
}

int main()
{
    //freopen("in.txt", "r", stdin);
    init();
    bfs();

    string tmp;
    int in[9];
    while (cin >> tmp){
        if (tmp[0] == 'x')in[0] = 0;
        else in[0] = tmp[0] - '0';
        for (int i = 1; i<9; ++i){
            cin >> tmp;
            if (tmp[0] == 'x')in[i] = 0;
            else in[i] = tmp[0] - '0';
        }
        int status = encodeCantor(in);
        if (!vis[status])cout << "unsolvable" << endl;
        else {
            int len = strlen(path[status]);
            for (int i = len - 1; i >= 0; --i)printf("%c", path[status][i]);
            printf("\n");
        }
    }

    return 0;
}


第二种记录路径的方法,速度更快,内存更小

//记录上一个stauts

#include <iostream>
#include <cstdio>
#include <memory.h>
#include <queue>
#include <string>
#include <cstring>

using namespace std;
const int maxn = 362880 + 5;
int fac[9];
int vis[maxn];

int dx[] = { -1, 1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };
char dir[]="durl";

struct node
{
public:
    node(int p, int s) :pos(p), status(s){}
public:
    int pos;
    int status;
};

struct path
{
public:
    int from, dir;
}p[maxn];

void calFac(int *f, int n)
{
    f[0] = 1;
    for (int i = 1; i<n; ++i)f[i] = f[i - 1] * i;
}
int encodeCantor(int *s)
{
    int i, j, num, temp;
    num = 0;
    for (i = 0; i<9; ++i){
        temp = 0;
        for (j = i + 1; j<9; ++j){
            if (s[j]<s[i])
                temp++;
        }
        num += fac[9 - 1 - i] * temp;
    }
    return num;
}

void decodeCantor(int *s, int val)
{
    bool flag[10];
    memset(flag, 0, sizeof(flag));
    for (int i = 0; i<9; ++i){
        int _rank = val / fac[8 - i];
        for (int j = 0; j <= _rank; ++j){
            if (flag[j]){
                _rank++;
            }
        }
        s[i] = _rank;
        flag[_rank] = true;;
        val = val%fac[8 - i];
    }
}

bool check(int x, int y)
{
    if (x<0 || y<0 || x>2 || y>2)return false;
    else return true;
}


void bfs()
{
    queue<node>q;
    int s[] = { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
    node n(8, encodeCantor(s));
    vis[n.status] = 1;
    p[n.status].from = -1;
    q.push(n);
    while (!q.empty()){
        n = q.front();
        q.pop();
        int x = n.pos / 3; int y = n.pos % 3;
        for (int i = 0; i<4; ++i){
            int newx = x + dx[i];
            int newy = y + dy[i];
            if (!check(newx, newy))continue;
            int newpos = newx * 3 + newy;
            decodeCantor(s, n.status);
            swap(s[n.pos], s[newpos]);
            int nstatus = encodeCantor(s);
            if (!vis[nstatus]){
                p[nstatus].from = n.status;
                p[nstatus].dir = i;
                vis[nstatus] = 1;
                q.push(node(newpos, nstatus));
            }
            swap(s[n.pos], s[newpos]);
        }

    }

}

void print(int s)
{
    while (p[s].from != -1)
    {
        printf("%c", dir[p[s].dir]);
        s = p[s].from;
    }
    printf("\n");
}

void init()
{
    calFac(fac, 9);
    memset(vis, 0, sizeof(vis));
}

int main()
{
    //freopen("in.txt", "r", stdin);
    init();
    bfs();

    string tmp;
    int in[9];
    while (cin >> tmp){
        if (tmp[0] == 'x')in[0] = 0;
        else in[0] = tmp[0] - '0';
        for (int i = 1; i<9; ++i){
            cin >> tmp;
            if (tmp[0] == 'x')in[i] = 0;
            else in[i] = tmp[0] - '0';
        }
        int status = encodeCantor(in);
        if (!vis[status])cout << "unsolvable" << endl;
        else {
            print(status);
        }
    }

    return 0;
}

境界四、双向BFS+康托判重+剪枝


图转自http://www.cnblogs.com/JMDWQ/archive/2012/05/20/2510698.html

如图,双向bfs可以节约一半的时间和空间,注意境界一复杂度时9!,现在是9!/2,还不够快。

故注意进行奇偶剪枝,否则会TLE

剪枝原理:

       逆序数:对于n个不同的元素,先规定各元素之间有一个标准次序(例如n个 不同的自然数,可规定从小到大为标准次序),于是在这n个元素的任一排列中,当某两个元素的先后次序与标准次序不同时,就说有1个逆序。逆序对的总数称为逆序数

       只要终止状态和起始状态的逆序数(空的位置不算)奇偶性不同,就一定不能达到目标状态。

       分析:向左或者向右移动,逆序数的奇偶行不变....0,xt,xt+1...,将.0和xt交换,奇偶性是不变的

       对 x1  x2  x3

           x4   x5  x6

           x7   0    x8

      将0和x5交换,x1  x2  x3  x4   x5  x6 x7   0    x8,下面分三种情况

     a)若 x5>x6 && x5> x7,则逆序数+2

     a)若 x5 <x6 && x5<x7,则逆序数-2

     a)若 x5 在6 和x7之间,则逆序数不变

通过以上分析可知:只有起始状态可终止状态逆序数奇偶性相同才能转换


双向bfs,采用两个队列q1和q2,一个从起始状态向目标状态扩展,另一个从目标状态像起始状态扩展

判别重可以采用

int vis[manx];//q1为1,q2为2

//可以用
bool vis1[maxn],vis2[maxn];


输出路径时

q1的另用一个数组记录下来

char tmp[36]; int len = 0;
    while (p1[s]!= -1){
        tmp[len++] = dir1[d1[s]];
        s = p1[s];
    }
q2利用和境界三一样的方法


代码如下

#include <stdio.h>
#include <queue>
#include <memory.h>
using namespace std;

const int maxn = 362880 + 5;
char *dir1 = "udlr";
char *dir2 = "durl";

int dx[] = { -1, 1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };

struct node
{
public:
    int status, pos;
};

int p1[maxn], p2[maxn];
int d1[maxn], d2[maxn];
bool vis1[maxn],vis2[maxn];
int fac[9];
void init()
{
    fac[0] = 1;
    for (int i = 1; i<9; ++i){
        fac[i] = i*fac[i - 1];
    }

}

int encodeCantor(int *s)
{
    int _rank, sum = 0;
    for (int i = 0; i < 9; ++i){
        _rank = 0;
        for (int j = i + 1; j<9; ++j){
            if (s[i]>s[j])_rank++;
        }
        sum += fac[8 - i] * _rank;
    }
    return sum;
}

void decodeCantor(int *arr, int s)
{
    bool flag[9];
    memset(flag, 0, sizeof(flag));
    for (int i = 0; i<9; ++i){
        int _rank = s / fac[8 - i];
        for (int j = 0; j <= _rank; ++j){
            if (flag[j])_rank++;
        }
        arr[i] = _rank;
        flag[_rank] = 1;
        s = s%fac[8 - i];
    }
}

bool check(int x, int y)
{
    if (x<0 || y<0 || x>2 || y>2)return false;
    else return true;
}

void print(int status)
{
    int s = status;
    char tmp[36]; int len = 0;
    while (p1[s]!= -1){
        tmp[len++] = dir1[d1[s]];
        s = p1[s];
    }
    s = status;
    for (int i = len - 1; i >= 0; i--)printf("%c", tmp[i]);
    while (p2[s] != -1){
        printf("%c", dir2[d2[s]]);
        s = p2[s];
    }
    printf("\n");
}

void bfs(int init_pos, int init_status)
{
    queue<node>q1, q2;
    memset(vis1, 0, sizeof(vis1));
    memset(vis2, 0, sizeof(vis2));
    int arr[9];
    int aim[] = { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
    int aim_s = encodeCantor(aim);
    node n;
    n.status=init_status;
    n.pos=init_pos;
    q1.push(n);
    n.status=aim_s;
    n.pos=8;
    q2.push(n);

    node cur;
    node next;

    p1[init_status] = -1;
    p2[aim_s] = -1;
    vis1[init_status] = 1;
    vis2[aim_s] = 1;
    int flag;
    while (!q1.empty() || !q2.empty()){
        if (!q1.empty() && (q2.empty() || q1.size() <= q2.size())) {//选择较少的扩展,效率较高
            flag = 1;
            cur = q1.front();
            q1.pop();
            if (vis2[cur.status]){
                print(cur.status);
                return;
            }
        }
        else {
            flag = 2;
            cur = q2.front();
            q2.pop();
            if (vis1[cur.status]){
                print(cur.status);
                return;
            }
        }
        decodeCantor(arr, cur.status);
        int x = cur.pos / 3; int y = cur.pos % 3;
        for (int i = 0; i<4; ++i){

            int nx = x + dx[i]; int ny = y + dy[i];
            if (!check(nx, ny))continue;
            int newpos = nx * 3 + ny;
            swap(arr[cur.pos], arr[newpos]);
            int nstatus = encodeCantor(arr);
            if (flag == 1 && !vis1[nstatus]){
                p1[nstatus] = cur.status;
                d1[nstatus] = i;
                if (vis2[nstatus]){
                    print(nstatus);
                    return;
                }
                else {
                    vis1[nstatus] = 1;
                    next.status=nstatus;
                    next.pos=newpos;
                    q1.push(next);
                }
            }
            else if (flag == 2 && !vis2[nstatus]){
                p2[nstatus]= cur.status;
                d2[nstatus] = i;
                if (vis1[nstatus]){
                    print(nstatus);
                    return;
                }
                else{
                    vis2[nstatus] = 1;
                    next.status=nstatus;
                    next.pos=newpos;
                    q2.push(next);
                }
            }

            swap(arr[cur.pos], arr[newpos]);
        }

    }
    return;
}

//奇偶剪枝
bool pruning(int *arr){
    int flag = 0;
    for (int i = 0; i<9; ++i){
        if (arr[i] == 0) continue;
        for (int j = i + 1; j<9; ++j){
            if (arr[j] && arr[i]>arr[j]) flag++;
        }
    }
    if (flag % 2) return true;
    return false;
}

int main()
{
    //freopen("in.txt", "r", stdin);
    char tmp[3];
    int in[9];
    int pos;
    init();
    while (scanf("%s", tmp) != EOF){

        if (tmp[0] == 'x'){
            in[0] = 0;
            pos = 0;
        }
        else in[0] = tmp[0] - '0';
        for (int i = 1; i<9; ++i){
            scanf("%s", tmp);
            if (tmp[0] == 'x'){
                in[i] = 0;
                pos = i;
            }
            else in[i] = tmp[0] - '0';
        }
        int status = encodeCantor(in);
        if (pruning(in))printf("unsolvable\n");
        else {
            bfs(pos, status);
        }
    }
    return 0;
}

境界六、A*+cantor判重+曼哈顿距离

境界五和境界六差不多,就是启发式函数使用的不一样,直接写了境界六

参考理解A*寻路算法具体过程

启发式算法的估价函数为 f(n) = g(n) + h(n)

     G 表示从起点 A 移动到网格上指定方格的移动耗费 (可沿斜方向移动).

     H 表示从指定的方格移动到终点 B 的预计耗费 (H 有很多计算方法, 这里我们设定只可以上下左右移动).

A*算法的估价函数可以表示为

       f'(n) = g'(n) + h'(n) 
       f’(n)是估价函数,g’(n)是起点到终点的最短路径值,h’(n)是n到目标的最断路经的启发值。由 于这个f’(n)其实是无法预先知道的,所以我们用估价函数f(n)做近似。g(n)代替g’(n),但 g(n)>=g’(n) 才可(大多数情况下都是满足的,可以不用考虑),h(n)代替h’(n),但h(n)<=h’(n)才可(这一点特别的重 要)。


这里的G指的是bfs扩展的层数,因为一层就是一步

           H指的是当前位置到终点的曼哈顿距离


计算曼哈顿距离的函数为

int getH(int *arr)
{
    int x, y;
    int h = 0;
    for (int i = 0; i<9; ++i){
        if (arr[i]){
            x = i / 3;
            y = i % 3;
            h += abs(x - tx[arr[i]]) + abs(y - ty[arr[i]]);//tx,ty分别表示arr[i]的目标位置坐标
        }
    }
    return h;
}


上代码

#include <iostream>
#include <stdio.h>
#include <queue>
#include <memory.h>
#include <stdlib.h>
using namespace std;
const int maxn = 362880 + 5;
int fac[] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320 };
char *dir = "udlr";
int dx[] = { -1, 1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };
bool vis[maxn];

struct node
{
    int status, pos;
    int g, h;
    bool operator<(const node&n)const{
        return (g + h)>(n.g + n.h);
    }
};

struct path
{
    int from, dir;
}p[maxn];

int tx[] = { 2, 0, 0, 0, 1, 1, 1, 2, 2 };
int ty[] = { 2, 0, 1, 2, 0, 1, 2, 0, 1 };

int encodeCantor(int *arr)
{
    int sum = 0;
    for (int i = 0; i<9; ++i){
        int _rank = 0;
        for (int j = i + 1; j<9; ++j){
            if (arr[i]>arr[j])_rank++;
        }
        sum += _rank*fac[8 - i];
    }
    return sum;
}

void decodeCantor(int *arr, int val)
{
    int flag[9], _rank;
    memset(flag, 0, sizeof(flag));
    for (int i = 0; i<9; ++i){
        _rank = val / fac[8 - i];
        for (int j = 0; j <= _rank; ++j){
            if (flag[j])_rank++;
        }
        arr[i] = _rank;
        flag[_rank] = 1;
        val = val%fac[8 - i];
    }
}

int getH(int *arr)
{
    int x, y;
    int h = 0;
    for (int i = 0; i<9; ++i){
        if (arr[i]){
            x = i / 3;
            y = i % 3;
            h += abs(x - tx[arr[i]]) + abs(y - ty[arr[i]]);
        }
    }
    return h;
}

bool pruning(int *arr)
{
    int sum = 0;
    for (int i = 0; i<9; ++i){
        if (!arr[i])continue;
        for (int j = i + 1; j<9; ++j){
            if (arr[j]&&arr[i]>arr[j])sum++;
        }
    }
    if (sum % 2)return true;
    else return false;
}

bool check(int x, int y)
{
    if (x<0 || y<0 || x>2 || y>2)return false;
    else return true;
}

void A_star(int *arr)
{
    int aim[] = { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
    int aim_s = encodeCantor(aim);
    priority_queue<node>q;
    memset(vis, 0, sizeof(vis));
    node cur, next;
    int status = encodeCantor(arr);
    for (int i = 0; i<9; ++i){
        if (!arr[i]){
            cur.pos = i;
            break;
        }
    }
    cur.status = status;
    cur.g = 0;
    cur.h = getH(arr);
    q.push(cur);
    p[status].from = -1;
    vis[status] = 1;
    while (!q.empty()){
        cur = q.top();
        q.pop();
        decodeCantor(arr, cur.status);
        if (cur.status == aim_s){
            int s = cur.status, len = 0;
            char res[maxn];
            while (p[s].from != -1){
                res[len++] = dir[p[s].dir];
                s = p[s].from;
            }
            for (int i = len - 1; i >= 0; i--){
                printf("%c", res[i]);
            }
            printf("\n");
            return;
        }
        else{

            int x = cur.pos / 3; int y = cur.pos % 3;
            for (int i = 0; i<4; ++i){
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (!check(nx, ny))continue;
                int newpos = nx * 3 + ny;
                swap(arr[newpos], arr[cur.pos]);
                int nstatus = encodeCantor(arr);
                if (!vis[nstatus]){
                    next.status = nstatus;
                    next.pos = newpos;
                    next.g = cur.g + 1;
                    next.h = getH(arr);
                    p[next.status].from = cur.status;
                    p[next.status].dir = i;
                    vis[next.status] = 1;
                    q.push(next);
                }
                swap(arr[newpos], arr[cur.pos]);
            }
        }
    }
    printf("unsolvable\n");

}

int main()
{
    //freopen("in.txt", "r", stdin);
    char tmp[5];
    int in[9];
    while (scanf("%s", tmp) != EOF){
        if (tmp[0] == 'x')in[0] = 0;
        else in[0] = tmp[0] - '0';
        for (int i = 1; i<9; ++i){
            scanf("%s", tmp);
            if (tmp[0] == 'x')in[i] = 0;
            else in[i] = tmp[0] - '0';
        }
        //int status=encodeCantor(in);
        if (pruning(in))printf("unsolvable\n");
        else A_star(in);
    }
    return 0;
}





alpha-beta剪枝八数码的实现 我用的alpha -beta剪枝算法,实现的八数码问题。需要的可以去看看。 立即下载

相关推荐

【AIGC】人工智能训练师(高级)考试题库-橙点同学

例如,在嘈杂的环境中进行声音转文字,即使是优秀的模型也可能会出现一些错误,但这并不意味着该模型本身质量差,在其他较为理想的环境下,它可能会有很好的表现。例如,在一些语音应用和系统中,会使用SSML来实现对语音合成的精细控制,如调整语速、语调、音量等,而这些应用和系统的开发往往会遵循W3C的相关标准和框架,其中就包括SSML这一语音合成标记语言。例如,在语音识别等场景中,像“去火车站怎么走”这样的语音指令,没有其他嘈杂的背景声音或模糊不清的表述,就属于无噪音的数据,有利于系统准确地进行处理和分析。

RisunJan的博客 9972

hdu 1043 八数码 单向广搜

从目标解开始广搜,就是打表,记录所有可以到目标解的路径,在HDU很容易超空间。 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1043 #include #include #include #include #include #include using namespace std; int ctarray[10] ={1,1,2,

NM的专栏 674

FPGA:UART串口接收(高干扰情况)

在上一篇文章中介绍过UART串口接收模块,其中一个需要优化的方向就是在高干扰情况下,如何实现可靠的UART串口接收任务。

weixin_50164178的博客 1681

【HDU No. 1043】 八数码 Eight

【HDU No. 1043】 八数码 Eight

代码改变世界 923

Linux系统杀毒软件深度评测:8款主流工具对比(2025最新版)

本文针对Linux服务器/桌面环境,实测8款杀毒软件,涵盖开源免费、企业级防护、轻量级工具等类型,附保姆级安装教程和避坑指南,新手也能5分钟选对工具!

awei0916的专栏 1万+

模拟调制系统实战:从AM到FM的5种调制方式对比与选型指南

本文深度解析AM、DSB、SSB、VSB、FM五种经典模拟调制方式,从实现电路、频谱效率、抗噪性能及工程成本等维度进行实战对比。通过MATLAB/Simulink仿真案例,提供清晰的选型决策框架,帮助工程师在无人机图传、短波通信、广播系统等具体项目中,根据带宽、功耗和抗干扰需求选择最优方案。

study的专栏 946

HDU 1043 广搜,优先队列,A*算法

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1043 15谜题已经有100多年历史了。即使不知其名,肯定也见过。它由15个滑动块组成,每个滑动块由数字1到15标记,并且被放在4x4大小的框框里面,缺失一个块。缺失的称之为x。谜题的目标就是将这些块有序的整理起来。如下图: 1 2 3 4 5 6 7 8 9 10 11 12...

P19777的博客 411

DolphinScheduler租户配置踩坑实录:手把手教你修复‘tenant not exists‘报错

本文深度解析DolphinScheduler的租户模型,并提供一套从界面到数据库的系统性排查流程,手把手教你修复常见的'tenant not exists'报错。文章揭示了该错误的本质是用户与租户数据关联不一致,并给出了通过UI或SQL更新的具体修复方案,同时分享了根因分析与预防措施,帮助用户从根本上理解和避免此类问题。

2w3e4r5t6y的博客 547

A - Eight HDU - 1043(A*算法、双向bfs)

A - Eight HDU - 1043(A*算法、双向bfs) 题意 给我们 8个数(1,23…)和一个字母x组成的一个序列,让我们通过 上下左右移动x操作,把这个序列变成:1 2 3 4 5 6 7 8 x 思路一 双向bfs 我们先考虑,什么是 双向bfs ?,简单的说就是,从起点、终点两个方向开始 bfs搜索, 这个算法的实现是通过 两个队列 q1、q2q1、q2q1、q2, 我们分别把起点、终点的搜索状态 压入q1、q2q1、q2q1、q2, 再通过 vis1[&nbsp

做一只熊猫不好吗? 427

数学建模学习(75):全局敏感性分析Morris 方法

敏感性分析 (SA) 是分析不同应用条件下模型行为的基本实践。提出了许多 SA 技术,从简单的筛选方法到计算成本高昂的基于方差的方法。本篇内容我们通过将 Morris 方法来对模型进行分析。

全栈川川 1万+

YOLOv13改进策略【Neck篇】| GSConv 轻量卷积,Slim-Neck 减参数还不掉点

Neck 篇的第二篇继续"替换式"改进,这次的对象是 Neck 里的下采样卷积。GSConv 出自《Slim-neck by GSConv: a better design of lightweight detector》(2022),它的出发点:DWSConv(深度可分离)轻但"信息混不进通道",标准卷积重但表达好——GSConv 用GConv(分组卷积)混通道 + DWConv 补空间 + Channel Shuffle 打散,两全其美。

qq_53329130的博客 40

逆向bfs搜索打表+康拓判重

HDU 1043八数码问题   八数码,就是1~8加上一个空格的九宫格,这道题以及这个游戏的目标就是把九宫格还原到从左到右从上到下是1~8然后最后是空格。   没了解康托展开之前,这道题怎么想都觉得很棘手,直接搜索的话也不知道怎么剪枝,而且判重也不可能开一个9维的数组,空间也不允许,所以先了解康托展开是无可厚非的第一步,这里就引用一下大佬的介绍,很简单很实用的关于全排列的一个东西   康...

weixin_30532759的博客 126

YOLOv11改进-卷积-引入小波卷积WTConv 解决多尺度小目标问题

1.首先,WTConv利用二维Haar小波变换对输入图像进行多级分解。低频分量 (LL):捕捉图像的低频信息,如整体形状或轮廓。水平高频分量 (LH):捕捉图像中的水平边缘信息。垂直高频分量 (HL):捕捉图像中的垂直边缘信息。对角线高频分量 (HH):捕捉图像的对角线细节。在每一级的小波变换中,图像被下采样(空间分辨率减半),但频率信息得到了更细的分解。递归地执行小波变换(称为多级分解)可以得到不同尺度下的频率分量。

qq_64693987的博客 1万+

hdu 1043(经典搜索)

题意: 给你一个初始的图,然后每次输入一个图,要求移动x最小的步数达到和初始图一样,输出路径 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 5 6 7 8 5 6 7 8 5 6 7 8 5 6 7 8 9 x 10 12 9 10 x 12 9 10

阳光下的泡沫 593

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

hdu1043八数码的八境界

大学一年了什么都不会,最近又什么都不想学,可是离正式打比赛还有仅仅半年,咨询了好多个学长我现在该学什么,如何静下心学习。考虑了好九八,决定步上jh学长的后路学习一下A*搜索。那么接下来开始?! 写之前拜读了这篇文章:八数码的八境界 境界一、 暴力广搜+STL 我们从{1,2,3,4,5,6,7,8,x}这个状态开始搜索,利用bfs跑遍每一种状态,并将path记录,复杂度9!,查询O(1) 判重我...

Hi_puppy 353

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

poj 1077 Eight (八数码问题——A*+cantor展开+奇偶剪枝)

题目来源: http://poj.org/problem?id=1077 题目大意: 给你一个由1到8和x组成的3*3矩阵,x每次可以上下左右四个方向交换。求一条路径,得到12345678x这样的矩阵。若没有路径,则输出unsolvable。 经典的八数码问题。 这题我用A*算法做的。推荐一篇博客,从大体上介绍了一下启发式算法的代表A*算法: https://www.cnb...

weixin_30398227的博客 214

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

HDU 1043 八数码问题的多种解法

一、思路很简单,搜索。对于每一种状态,利用康托展开编码成一个整数。于是,状态就可以记忆了。 二、在搜索之前,可以先做个优化,对于逆序数为奇数的序列,一定无解。 三、搜索方法有很多。   1、最普通的:深搜、广搜。在这题里面,这两个方法直接TLE。所以,我后面没有贴超时的代码。   2、既然1超时,那就预处理出所有状态,用map存储,然而,map的insert(使用[]是一样的)实在太慢了,...

weixin_34248487的博客 269

HDU - 1043

八数码: 这里面需要了解一个康托展开式:a,b,c,d,e n=4!*a[0]+3!*a[1]+2!*a[2]+1!*a[3]+0!*a[4],a[ ]数组里面的值为从这个数开始,往后有几个比它小的数。用康托展开式可以求3*3这个图的状态(我理解为状态压缩成一个值)。 思路:需要用到广搜,如果从给定状态到0去搜,将输入的X当成9,与相邻数字交换值(因为9是在游戏中空格),四个方向广搜 ,...

HappyCode 223

八数码 HDU - 1043(状态压缩,宽搜)

题面题意 3*3的方格中有一个x,可以将x与它相邻的方块交换,使最终结果为 1 2 3 4 5 6 7 8 x 方法 用康拓展开式的方法,状压(也可以采用哈希表),然后通过不断的转换实现用1~362880(9!)来记录3*3中数字的状态 记录时,用9来代替x 再进行宽搜(从最终状态开始),用一个数组来记录达到各个状态之前的状态,并用另一个数组记录这次的移动 代码

yzyyylx的博客 651

双向BFS:字串变换

题目链接:https://www.acwing.com/problem/content/description/192/ 题目: 已知有两个字串A,B及一组字串变换的规则(至多6个规则): A1→B1 A2→B2 … 规则的含义为:在AA中的子串A1A1可以变换为B1B1、A2A2可以变换为B2…B2…。 例如:AA=abcdBB=xyz 变换规则为: abc→→xuud→→yy→→yz 则此时,AA可以经过一系列的变换变为BB,其变换的过程...

qq_49120553的博客 180

HDU 1043 八数码问题【双向BFS】

HDU 1043 八数码问题【双向BFS】 题目链接 题意:给你一个初始状态,问你能否移动到最终的完成状态,如果能输出任意一组解,否则输出unsolved。 思路:乍一看是个BFS,但是状态过多会TLE或者MLE,但是除可BFS确实没得写了,这时候就要用到双向BFS了,起点终点同时BFS,判断相遇,路径用string+就行了。 注意点:正向路径s=s+c,逆向s=c+s;输出也要注意先输出正向; ...

qq_43653111的博客 265

【HDU-1043】Eight 八数码(BFS之A*算法)

15 块拼图已有 100 多年的历史,即使你不知道它的名字,也一定见过它。它由 15 块滑动瓷砖组成,每块瓷砖上都有一个从 1 到 15 的数字,所有瓷砖都被装在一个 4×4 的框架内,其中缺少一块瓷砖。我们把这块缺失的瓷砖称为 "x";谜题的目的是将瓷砖排列成以下顺序: 其中唯一合法的操作是将 "x "与与它共享一条边的其中一块牌交换。举例来说,下面的移动顺序可以解决一个略微混乱的谜题:

Tom的博客 808

算法百题斩其二: 双向bfs——bfs的一种优化

算法百题斩其二: 双向bfs——bfs的一种优化 写在前面:何所谓“斩”? 斩,即快速而有力地切断,指我们用最精简的语言,一针见血地点破算法题的核心难点。斩需三思而后行;斩需借助外力、旁征博引;斩需持之以恒、铁杵磨针! 1. 何为双向bfs? 是啥? 在知道初态和末态、且从两个方向产生的搜索树可覆盖所有(合法)状态的情况下,通过从起点和终点分别进行bfs,直到形成的两个连通块相交(若不交则无解),产生深度减半的搜索树。一般地,选择点集较小的那一侧进行下一次的延申操作,可以最小化“浪费”的状态,或者更直观地

weixin_54648192的博客 1181
上一篇: 第四章 function语意学(二)
下一篇: hdu1044(bfs+dfs/bfs+状态压缩)
pmt123456
博客等级 码龄12年 74粉丝 165原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值