本文章由 WyOJ Shojo 从洛谷专栏拉取,原发布时间为 2022-07-27 09:32:51
题解思路:
我们要构造一个 $01$ 串 $s$,使得 $s$ 的长度是 $\le 2\cdot t$,使得 $k$ 最小。 $k$ 指的是 $s_i = s_{i + k}$,那么 $k$ 就是 $s$ 的周期。 那么当 $t$ 是全零或者全一的,那么直接输出 $t$ 就可以了。 否则输出 $0101...01$,因为 $k=2$,最小的了。
#include <iostream>
using namespace std;
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
string s;
cin >> s;
bool ok = false, ok2 = false;
for (auto x : s)
{
if (x == '1')
ok = true;
else
ok2 = true;
}
if (!ok || !ok2)\/\/全0或者全1
{
cout << s << endl;
continue;
}
for (int i = 0; i < s.size(); ++i)\/\/输出01
printf("01");
putchar('\n');
}
return 0;
}

鲁ICP备2025150228号