【题解】位运算01串
题意
给你两个字符串
,问是否可以通过操作将
串转化为
串。操作为从
串中可以任取
然后令
,然后将
用
或
进行替换。
题解
首先可以发现变换规律为 。
那么若串为全
串的话是肯定可以变为
串的(除非
串为全
串)。
由于存在,所以可以将
串全变为
若
串中有
时。
所以结论就是当串中有
且
串中有
时,是可以转化的,或两个串都是全
串,但是一个是全
,另一个中有
时就不能了。
复杂度
时间复杂度
代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
string A,B;
cin>>A>>B;
if(A==B||(A.length()==B.length()&&A.find('1')!=-1&&B.find('1')!=-1))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
