原题链接: https://codeforces.com/contest/1400/problem/A
测试样例:
input
4
1
1
3
00000
4
1110000
2
101
output
1
000
1010
00
Note:
The explanation of the sample case (equal characters in equal positions are bold):
The first test case:
1 is similar to s[1…1]=1.
The second test case:
000 is similar to s[1…3]=000;
000 is similar to s[2…4]=000;
000 is similar to s[3…5]=000.
The third test case:
1010 is similar to s[1…4]=1110;
1010 is similar to s[2…5]=1100;
1010 is similar to s[3…6]=1000;
1010 is similar to s[4…7]=0000.
The fourth test case:
00 is similar to s[1…2]=10;
00 is similar to s[2…3]=01.
题意: 定义两个二进制字符串相似的规则为某一位置上字符相同。你会得到一个长度的二进制字符串。现你需构造一个长度为
的二进制字符串
,它相似于以下所有字符串:
。
解题思路: 构造的思路就是寻求最简最优构造方案。我们先想想,怎么样才算相似?对应位置下标相同和字符相同。 那么,我们现在构造的二进制字符串需要相似个字符串,你可能会觉得有点不太现实,因为我们构造的字符串长度也才
。那么我们应该怎样去想?我们看这
个字符串,对其字符串编号。那么我们是不是都可以从第
个字符串中取出第
个字符构造。那么不就刚刚一一对应相似了吗? (即构造字符串中第
个位置上的字符为与第
个字符串相似的决定性因素。)这样我们就发现思路了,要记得字符串之间要跨越2才可以进入下一个字符串的下一个位置。具体实现看代码。
AC代码:
/*
、
*
*/
//POJ不支持
//i为循环变量,a为初始值,n为界限值,递增
//i为循环变量, a为初始值,n为界限值,递减。
using namespace std;
const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//
int t,n;
string s;
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
cin>>n>>s;
for(int i=0;i<2*n-1;i+=2)
cout<<s[i];
cout<<endl;
}
}
return 0;
}