为什么CE?
  • 板块灌水区
  • 楼主a_small_penguin
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/6 17:35
  • 上次更新2025/1/6 17:48:39
查看原帖
为什么CE?
767155
a_small_penguin楼主2025/1/6 17:35

这段代码为什么CE:

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

int k;
string a, b;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> k;
    cin >> a >> b;
    a = " " + a;
    b = " " + b;
    
    queue<pair<string, int> > q;
    q.push({a, 0});
    while(q.size()) {
        int dist = q.front().second;
        string s = q.front().first;
        
        if(dist > k) break;
        if(s == b){
            cout << "Yes";
            return 0;
        }
        
        q.pop();
        for(int i = 1;i < max((int)s.size(), (int)b.size()); i++){
            if(s[i] != b[i]){
                string t = s;
                t[i] = b[i];
                q.push({t, dist + 1});
                
                t = s;
                t.insert(i, b[i]);
                q.push({t, dist + 1});
                
                t = s;
                t.erase(i, 1);
                q.push({t, dist + 1});
                break;
            }
        }
    }
    
    cout << "No";
    
    return 0;
}


2025/1/6 17:35
加载中...