CodeForces 282C(位运算)
2 seconds
256 megabytes
standard input
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.
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.
Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.
11
10
YES
1
01
NO
000
101
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(位运算)的更多相关文章
- Codeforces 76D 位运算
题意:给你两个数x 和 y, x = a + b, y = a XOR b,问有没有合法的a和b满足这个等式? 思路:有恒等式: a + b = ((a & b) << 1) + ...
- Codeforces - 912B 位运算
求[1,n]内k的值的异或和使其值最大 k=1是肯定是n k>1,设pos是n的最高位,那答案就是(1ll<<(pos+1))-1 这里用到一个性质是当S=2^i-1时,a xor ...
- Codeforces 868D Huge Strings - 位运算 - 暴力
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...
- 图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest
题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #443 (Div. 2) C 位运算
C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces 620E New Year Tree(线段树+位运算)
题目链接 New Year Tree 考虑到$ck <= 60$,那么用位运算统计颜色种数 对于每个点,重新标号并算出他对应的进和出的时间,然后区间更新+查询. 用线段树来维护. #includ ...
随机推荐
- iOS开发——项目篇—高仿百思不得姐
01 一.包装为导航控制器 UINavigationController *nav = [[UINavigationController alloc] initWithRootViewControll ...
- UNITY3D在线更新之道-CSlight 使用总结
转自:http://blog.csdn.net/leonwei/article/details/39233775 最近做U3D的热更新,研究了各种方式无果后,最容易最先想到的方式就是利用c#的反射机制 ...
- HTML5的新特性及技巧分享总结
原文链接:http://www.aseoe.com/show-10-645-1.html?utm_source=tuicool&utm_medium=referral 1. 新的Doctype ...
- 1.xrange和range不要混了,2.range(len(xx))不如用enumerate
range()是列表, xrange()是迭代 >>> a = ['Mary', 'had', 'a', 'little', 'lamb'] >>> for i i ...
- 2015安徽省赛 I.梯田
http://xcacm.hfut.edu.cn/problem.php?id=1213 set + 搜索 姐姐是用搜索+二分做的,效率要高很多 #include<iostream> #i ...
- 40 网络相关函数(八)——live555源码阅读(四)网络
40 网络相关函数(八)——live555源码阅读(四)网络 40 网络相关函数(八)——live555源码阅读(四)网络 简介 15)writeSocket向套接口写数据 TTL的概念 函数send ...
- 基于用户相似性的协同过滤——Python实现
代码基本来自项亮的<推荐系统实践>,把书上的伪代码具体实现,还参考了https://www.douban.com/note/336280497/ 还可以加入对用户相似性的归一化操作,效果会 ...
- 【GoLang】golang 交叉编译 实现&工具
apt-get install gcc-mingw-w64 env CGO_ENABLED= GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc g ...
- 怎样将myeclipse里默认编码设置成utf-8
需要设置三个位置: [1]需要在 Preferences->general->content types->下角是文件编码,可以自己定义 [2]windows->Prefer ...
- Oracle 与 entity framework 6 的配置,文档
官方文档: http://docs.oracle.com/cd/E56485_01/win.121/e55744/intro001.htm#ODPNT123 Oracle 对 微软 实体框架 EF6 ...