题解:P14603 [NWRRC 2025] Defense Distance

· · 题解

分析

神秘构造题。

abc 按升序排列,则:

  1. 否则,设 s 为一个字母 auc+1a。则 t 长度为 a+1。它的最后 a+b-c 个字符为 b,其他为 a

    代码

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    int a,b,c,at,bt,ct;
    string s,t,u;
    cin>>a>>b>>c;
    at=a;
    bt=b;
    ct=c;
    if(at>bt) swap(at,bt);
    if(at>ct) swap(at,ct);
    if(bt>ct) swap(bt,ct);
    if(at+bt<ct)
    {
        cout<<"No";
        return 0;
    }
    u='a';
    s='a';
    for(int i=1;i<=ct+1;i++) t+='a';
    for(int i=1;i<=ct-bt;i++) u+='a';
    for(int i=1;i<=at-ct+bt;i++) u+='b';
    cout<<"Yes"<<endl;
    if(c>=a&&a>=b) cout<<u<<endl<<t<<endl<<s;
    else if(a>=b&&b>=c) cout<<t<<endl<<s<<endl<<u;
    else if(b>=c&&c>=a) cout<<s<<endl<<u<<endl<<t;
    else if(a>=c&&c>=b) cout<<s<<endl<<t<<endl<<u;
    else if(b>=a&&a>=c) cout<<t<<endl<<u<<endl<<s;
    else cout<<u<<endl<<s<<endl<<t;
    return 0;
    }