D. Double Strings Codeforces Round #806 (Div. 4)

传送门

题目:

 

 题意:给你n个字符串,问第i个字符串能不能通过任意两个出现的字符串组合成(可以是同一个),如果可以就输出1,不是就输出0;

思路:可以通过最长的字符串长度是8位来进行考虑,因为最长的字符串只有八位,可以从1到8循环截取的位置,然后以一个接近O(n)的时间解决。

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
string s[N];
map<string,ll>q;

int main()
{
	int t;
	sc_int(t);
	while(t--)
	{
		sc_int(n);
		q.clear();
		for(int i =0;i<n;i++){
		cin>>s[i];
		q[s[i]]=1;
		}

		for(int i =0;i<n;i++)
		{
			int t=1;
			for(int j=1;j<s[i].size();j++)
			{
				string a=s[i].substr(0,j);
				string b=s[i].substr(j);
				if(q[a]&&q[b])
				{
					t=0;
					cout<<"1";
					break;
				}
			}
			if(t)cout<<"0";
		}
		cout<<endl;
	}
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值