D. Binary Literature
生活随笔
收集整理的這篇文章主要介紹了
D. Binary Literature
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
D. Binary Literature
題意:
給三個長度為2 * n的01串,讓你構造一個長度小于3 * n的字符串,使得這個串至少包含兩個01串
題解:
很巧妙的構造題
三個指針分別指向三個串,因為是01串,所以一定存在兩個字符串指針所指位置相等,相等部分加入S串中(S串為最后的答案),直到一個串完全結束
然后剩下分析如圖
代碼:
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define pb push_back #define me memset const int N = 1e6 + 10; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; using namespace std; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; int main() {int t;cin>>t;while(t--){int n;cin>>n;string s1,s2,s3;cin>>s1>>s2>>s3;int len1=s1.length();int len2=s2.length();int len3=s3.length();int p1=0,p2=0,p3=0;string ans;while(p1<n*2&&p2<n*2&&p3<n*2){if(s1[p1]==s2[p2]){ans+=s1[p1];p1++;p2++;}else if(s1[p1]==s3[p3]){ans+=s1[p1];p1++;p3++;}else{ans+=s2[p2];p2++;p3++;}}// cout<<ans<<endl;if(p1>=2*n){if(p2>=p3) ans+=s2.substr(p2,2*n);else ans+=s3.substr(p3,2*n);}else if(p2>=2*n){if(p1>=p3) ans+=s1.substr(p1,2*n);else ans+=s3.substr(p3,2*n);}else{if(p1>=p2) ans+=s1.substr(p1,2*n);else ans+=s2.substr(p2,2*n);}cout<<ans<<endl;}return 0; }總結
以上是生活随笔為你收集整理的D. Binary Literature的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 制作母亲节贺卡 制作母亲节贺卡方法
- 下一篇: ios14支持哪些设备