0
点赞
收藏
分享

微信扫一扫

A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)

原题链接: ​​https://codeforces.com/contest/1400/problem/A​​

A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_思维
测试样例:

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.

题意: 定义两个二进制字符串相似的规则为某一位置上字符相同。你会得到一个长度A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_字符串_02的二进制字符串。现你需构造一个长度为A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_思维_03的二进制字符串A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_ios_04,它相似于以下所有字符串:A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_ios_05

解题思路: 构造的思路就是寻求最简最优构造方案。我们先想想,怎么样才算相似?对应位置下标相同和字符相同。 那么,我们现在构造的二进制字符串需要相似A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_思维_03个字符串,你可能会觉得有点不太现实,因为我们构造的字符串长度也才A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_思维_03。那么我们应该怎样去想?我们看这A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_思维_03个字符串,对其字符串编号。那么我们是不是都可以从第A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_思维_09个字符串中取出第A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_思维_09个字符构造。那么不就刚刚一一对应相似了吗? (即构造字符串中第A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_字符串_11个位置上的字符为与第A. String Similarity(思维+构造)Educational Codeforces Round 94 (Rated for Div. 2)_字符串_11个字符串相似的决定性因素。)这样我们就发现思路了,要记得字符串之间要跨越2才可以进入下一个字符串的下一个位置。具体实现看代码。

AC代码:

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

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;
}


举报

相关推荐

0 条评论