文章

25

粉丝

0

获赞

210

访问

6.2k

头像
玛雅人的密码 题解:
P1162 清华大学上机题
发布于2026年3月13日 15:11
阅读数 125

#include<bits/stdc++.h>
using namespace std;

struct Node{
    string s;
    int steps;
};
map<string,int> vis;

int BFS(string s){
    queue<Node>q;
    vis[s] = 1;
    q.push({s,0});

    while(!q.empty()){
        Node now = q.front();
        q.pop();

        if(now.s.find("2012") != std::string::npos){
            return now.steps;
        }

        for(int i = 0; i < now.s.size() - 1; i++){
            Node next;
            string str = now.s;
            swap(str[i],str[i+1]);
            next.s = str;

            if(vis[next.s])
              &...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发