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 ...
随机推荐
- Google Java编程风格指南中文版
作者:Hawstein出处:http://hawstein.com/posts/google-java-style.html声明:本文采用以下协议进行授权: 自由转载-非商用-非衍生-保持署名|Cre ...
- windows 下wamp环境3 安装php7
打开 http://php.net 点击download,选择Windows downloads,根据系统选择版本 注意左侧的提示: With Apache you have to use the T ...
- static小结
1.隐藏:编译多个文件时,所有未加static的全局变量.全局函数都具有全局可见性. 如果加了static,就会对其他源文件隐藏,利用这一特性可以在不同文件中定义相同的 变量名或函数名,而不用担心冲突 ...
- (转)一个JavaWeb项目开发总结
原文地址:http://www.cnblogs.com/lzb1096101803/p/4907775.html 一.学会如何读一个JavaWeb项目源代码 步骤:表结构->web.xml-&g ...
- Android 内容提供器(Content Provider)介绍
内容提供器(Content Provider)主要用于在不同的应用程序之间实现数据共享的功能,它提供了一套完整的机制,允许一个程序访问另一个程序中的数据,同时还能保证被访问数据的安全性.目前,使用内容 ...
- BestCoder Round #61 1001 Numbers
Problem Description There are n numbers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A1,A2....An,yo ...
- jenkins Auth fail验证失败
重新设置密码
- PhpExcel笔记,phpExcel中文帮助手册
下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...
- hdu 1195
题意:就是给你n组的四位数,在一次变化中又一位数字可以变化,而变化的方式为加一减一或者是与隔壁的互换,注意,是每一个数字都可以, 求最少的变化次数到达目标的数字 一看这个就应该知道这是一个bfs的题目 ...
- PHP输出Excel两种方法
2016年3月23日 16:43:51 星期三 第一种: 输出html+css格式, 打开后用Excel软件的"另存为"功能保存为正规的表格格式 public function e ...