Educational Codeforces Round 86 (Rated for Div. 2)B Binary Period
链接:https://codeforces.com/contest/1342/problem/B
题意:给个01串的子串t让找原串s,要使得周期最小:
满足条件:
1,字符串s只包含0和1;
2,s的长度不超过2⋅t (t是字符串t的长度);
3,字符串t是字符串s的子序列;
显然让s的周期最小只有两种情况,01间隔和全为相同的,
两种情况考虑一下输出即可:
code:
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N=2e5+5; int a[N]; int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } void solve() { string s; cin>>s; int n=s.size(); int flag=0; for(int i=0; i<n-1; i++) { if(s[i]!=s[i+1]) flag=1; } if(!flag) cout<<s<<endl; else { for(int i=0; i<n; i++) { cout<<s[i]; if(s[i]==s[i+1]) { if(s[i]=='1') cout<<0; else cout<<1; } } cout<<endl; } } int main() { int t; scanf("%d",&t); while(t--) solve(); //system("pause"); return 0; }