C. XOR and OR
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.

A Bitlandish string is a string made only of characters "0" and "1".

BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.

The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.

So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.

You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.

Input

The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths.

It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.

Output

Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.

Examples
Input
11
10
Output
YES
Input
1
01
Output
NO
Input
000
101
Output
NO

题意:给出两个字符串a, b,可以对a字符串中任意相邻的两个字符x,y进行位异或和按位或操作得到p=x^y;q=x|y;
再用p,q代替原来的x,y(可以交换顺序),问能否得到目标串b;
思路:
1:如果a和b的长度不同,则肯定不行;
2:由位运算法则我们可以知道有:
0^0=0, 0|0=0;
1^0=1, 1|0=1;
0^1=1, 0|1=1;
1^1=0, 1|1=1;
据此可以得知:(1,1)可以得到(0,1)或者(1,0);(0,1)或者(1,0)可以得到(1,1);(0,0)只能得到(0,0);
即有1的串不能完全消掉1(若a串长度为len1,且含有1,那么其可以得到一个含有x个1的串,x>=1&&x<=len1);没有1的串不能得到1;
所以只有当a,和b同时含有1或者不含1时可行; 代码:

 #include <bits/stdc++.h>
#define MAXN 100000+10
#define ll long long
using namespace std; int main(void)
{
std::ios::sync_with_stdio(false), cin.tie(), cout.tie();
string a, b;
cin >> a >> b;
int len1=a.size();
int len2=b.size();
if(len1!=len2)
{
cout << "NO" << endl;
return ;
}
if(len1==&&a[]=='')
{
if(b[]=='') cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}
int ans1=, ans2=;
for(int i=; i<len1; i++)
{
if(a[i]=='') ans1++;
if(b[i]=='') ans2++;
}
if(!ans1&&!ans2||ans1&&ans2)
cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}

 
艰难困苦,玉汝于成     ——————  geloutingyu

CodeForces 282C(位运算)的更多相关文章

  1. Codeforces 76D 位运算

    题意:给你两个数x 和 y, x = a + b, y = a XOR b,问有没有合法的a和b满足这个等式? 思路:有恒等式: a + b = ((a & b) << 1) + ...

  2. Codeforces - 912B 位运算

    求[1,n]内k的值的异或和使其值最大 k=1是肯定是n k>1,设pos是n的最高位,那答案就是(1ll<<(pos+1))-1 这里用到一个性质是当S=2^i-1时,a xor ...

  3. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  4. 图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest

    题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...

  5. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

  6. Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400

    题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...

  7. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】

    A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #443 (Div. 2) C 位运算

    C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. Codeforces 620E New Year Tree(线段树+位运算)

    题目链接 New Year Tree 考虑到$ck <= 60$,那么用位运算统计颜色种数 对于每个点,重新标号并算出他对应的进和出的时间,然后区间更新+查询. 用线段树来维护. #includ ...

随机推荐

  1. 使用ASP.Net WebAPI构建REST服务(一)——简单的示例

    由于给予REST的Web服务非常简单易用,它越来越成为企业后端服务集成的首选方法.本文这里介绍一下如何通过微软的Asp.Net WebAPI快速构建REST-ful 服务. 首先创建一个Asp.Net ...

  2. 如何开启telnet 23端口

    netstat -tnl|grep 23 查看23端口是否开启 或者 chkconfig --list|grep telnet 检查telnet状态 如果关闭状态, 开启:chkconfig --le ...

  3. Android ListView 图片异步加载和图片内存缓存

    开发Android应用经常需要处理图片的加载问题.因为图片一般都是存放在服务器端,需要联网去加载,而这又是一个比较耗时的过程,所以Android中都是通过开启一个异步线程去加载.为了增加用户体验,给用 ...

  4. 专业版Unity技巧分享:使用定制资源配置文件

    http://unity3d.9tech.cn/news/2014/0116/39639.html 通常,在游戏的开发过程中,最终会建立起一些组件,通过某种形式的配置文件接收一些数据.这些可能是程序级 ...

  5. UIMenuController使用

    - (void)bubbleDidLongPress:(UILongPressGestureRecognizer *)gestureRecognizer { if(gestureRecognizer. ...

  6. python 函数的文档字符串 docstrings

    函数体的第一行可以是一个可选的字符串文本:此字符串是该函数的文档字符串,或称为docstring.(更多关于 docstrings 的内容可以在 文档字符串一节中找到.)有工具使用 docstring ...

  7. 在Fedora 20 上安装Mysql并初始化root密码

    [root@localhost ~]# yum -y install community-mysql-server #安装数据库 已加载插件:langpacks, refresh-packagekit ...

  8. fastx_toolkit软件使用说明

    高通量测序数据下机后的原始fastq文件,包含4行,其中一行为质量值,另外一行则为对应序列,我们都了解高通量的数据处理首先要进行质量控制,这些过程包括去接头.过滤低质量reads.去除低质量的3'和5 ...

  9. Intellij IDEA使用总结

    查询快捷键CTRL+N   查找类CTRL+SHIFT+N  查找文件CTRL+SHIFT+ALT+N 查 找类中的方法或变量CIRL+B   找变量的来源CTRL+ALT+B  找所有的子类CTRL ...

  10. thinkphp save()方法没有数据,保存失败解决办法

    thinkphp save()方法没有数据保存返回0,保存失败返回false   可以对返回值判断一下就好 $ret = $model->save($data); //var_dump($ret ...