admin管理员组文章数量:1630208
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;
}
本文标签: binaryLiterature
版权声明:本文标题:D. Binary Literature 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729055946a1183962.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论