Codeforces Round #173 (Div. 2) / 282C XOR and OR (字符串处理)

工业互联网工控安全与工业质检AI大模型建设方案.pptx 立即下载

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.

Sample test(s)
input
11
10
output
YES
input
1
01
output
NO
input
000
101
output
NO

有如下变换:

1. 11<-->10

2. 11<-->01

3. 00-->00


由1和2知

4. 01<-->10

所以,只要两边长度相等,且两边都为0或者两边都有1,就输出"YES",其他为"NO"。


完整代码:

/*62ms,1900KB*/

#include<cstdio>
#include<cstring>
const int maxn = 1000001;

char a[maxn], b[maxn];

int main(void)
{
	bool chk1 = false, chk2 = false;
	gets(a);
	gets(b);
	int len1 = strlen(a), len2 = strlen(b), i;
	if (len1 != len2)
		printf("NO");
	else
	{
		for (i = 0 ; i < len1 && a[i] == '0' ; i++)
			;
		if (i < len1)
			chk1 = true;
		for (i = 0 ; i < len1 && b[i] == '0' ; i++)
			;
		if (i < len1)
			chk2 = true;
		printf(!chk1 && chk2 || chk1 && !chk2 ? "NO" : "YES");
	}
	return 0;
}

Haskell:

import qualified Data.ByteString.Char8 as B

main :: IO ()
main = putStrLn . solve . B.lines =<< B.getContents

solve :: [B.ByteString] -> String
solve (a : b : _)
  | B.length a == B.length b && B.elem '1' a == B.elem '1' b = "YES"
  | otherwise = "NO"


2024 《计算机网络》实验教学指导书.doc 立即下载

相关推荐

从NHANES到发表:如何用survey包完成符合CDC要求的统计分析(含完整R代码)

本文详细介绍了如何利用R语言的survey包,对美国国家健康与营养调查数据进行符合CDC要求的统计分析。文章重点解析了NHANES数据的复杂抽样设计、权重变量的正确选择与调整,并提供了从数据获取、清洗、构建调查设计对象到执行加权回归及生成发表级表格的完整R代码实战指南,帮助研究者避免常见错误,确保分析结果的准确性与可发表性。

weixin_29054245的博客 521

Haskell 语法基础

本周读完了 Haskell 入门文档,这里做一下笔记。 一、变量类型 变量 与命令式语言不同,Haskell 同一作用域内变量值不可改变。 r = 5 r = 2 -- error: multiple declarations of r 复制代码由于同一作用域变量值不可改变,所以变量定义可以是任意次序。 -- 如下的两种定义是等价的 -- A y = x * 2 x = 3 -- B x =...

weixin_34138377的博客 2132

cesium 高程数据使用

cesium 高程数据使用高程数据下载高程数据切片简单数据服务 高程数据下载 使用地理空间数据云平台免费提供的高程数据。地理空间云平台 点击列表中的下载得到数据压缩包。例如:ASTGTM2_N22E114.zip 高程数据切片 使用cesium实验室工具对下载得到的压缩包进行切片。cesium实验室 切片得到的文件夹目录。 简单数据服务 使用nodejs的koa启动简单的资源服务。koajs 项目根目录新建data文件夹,在新建dem文件夹放高程数据。 注意目录自行更换,这里是./data/dem

哎哟这个凉白白的博客 1811

Haskell语言学习笔记(2)

let-in where pattern-matching list tuple if-then-else case-of

zwvista的专栏 4109

3D Slicer隐藏技巧:这样玩转医学影像分割与3D建模(含DICOM处理)

本文深入探讨3D Slicer在医学影像分割与3D建模中的高级应用技巧,包括多模态分割策略、三维可视化优化及DICOM数据处理。通过专业配置和Python脚本示例,帮助医疗AI开发者和影像科医师提升工作效率,实现精准的医学图像分析与建模。

weixin_28559803的博客 432

2024.6.10丨基于DIAMOND与VFDB数据库的致病菌毒力因子高效注释指南

本文详细介绍了基于DIAMOND与VFDB数据库的致病菌毒力因子高效注释方法,涵盖工具安装、参数优化、数据库选择及实战案例解析。通过DIAMOND的快速比对和VFDB的全面毒力因子数据,显著提升微生物基因组研究效率,适用于临床检测、食品安全监测等多个场景。

weixin_33712987的博客 375

Codeforces Round #173 (Div. 2) <全>

题目链接: http://codeforces.com/contest/282   A题   Bit++ 题意:求出通过一系列自增自减运算最后变量的值。不用考虑前后。水题。 #include #include #include #include #include #include #include #include #include #include #include #define e

cc_again的专栏 1433

DMDiff(2025):一种基于SAR光学数据融合的双分支多模态条件引导扩散模型-k学长深度学习专栏

DMDiff提出了一种基于扩散模型的多模态遥感图像去云方法,通过双分支网络分别提取SAR的结构信息和光学图像的光谱特征,再利用跨模态注意力机制实现特征融合。创新性地采用IAP策略直接预测无云图像而非噪声,有效解决了传统方法在遥感图像处理中易出现的光谱失真问题。实验表明该方法在PSNR等指标上显著优于现有技术,但存在计算量大、生成速度慢等不足。未来可结合加速采样策略和几何约束进一步优化。

421

Manacher 算法详解:O(n) 复杂度求最长回文子串

先预处理下:在每个字符的两边都插入一个特殊的符号,比如abba变成#a#b#b#a#,aba变成#a#b#a#(因为Manacher算法只能处理奇数长度的字符串)。同时,为了避免数组越界,在字符串开头添加另一特殊符号,比如$#a#b#a#。 以字符串3212343219为例,处理后变成S[] = "$#3#2#1#2#3#4#3#2#1#9#"。 然后用一个数组Len[i]来记录以字符S[i

AC,∑ndless 4609

【WRF-Chem教程-附录 C】闪电-NOx 参数化方案详解

闪电-NOx 参数化方案详解

WW、forever的博客 974

ArcGIS JS 态势标绘教程:直箭头(Straight Arrow)

ArcGIS JS 态势标绘教程:直箭头(Straight Arrow)。

非科班Java出身GISer的博客 701

Codeforces Round #119 (Div. 2) / 189A Cut Ribbon (完全背包)

A. Cut Ribbon http://codeforces.com/problemset/problem/189/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 2675

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Codeforces Round #105 (Div. 2) / 148A Insomnia cure (枚举 || 数论)

A. Insomnia cure http://codeforces.com/problemset/problem/148/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 2453

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Codeforces Beta Round #74 (Div. 2) / 90B African Crossword (模拟)

B. African Crossword http://codeforces.com/problemset/problem/90%2FB time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard o

AC,∑ndless 2416

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Codeforces Round #173 (Div. 2) / 282A Bit++(模拟)

A. Bit++ http://codeforces.com/problemset/problem/282/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 2227

Codeforces Round #235 (Div. 2) / 410D Roman and Numbers (带有整除性质的数位DP)

http://codeforces.com/problemset/problem/401/D 解释全部在代码的注释中: /*78ms,205464KB*/ #include using namespace std; const int mx = 1 << 18; long long dp[mx][100]; ///dp[mask][j]表示余数为j时的mask对应的x的个数 ///

AC,∑ndless 2198

Codeforces Round #194 (Div. 1) / 333A Secrets(贪心)

A. Secrets http://codeforces.com/contest/333/problem/A time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ge

AC,∑ndless 2041

Codeforces Beta Round #98 (Div. 2) / 137A Postcards and photos (模拟)

A. Postcards and photos http://codeforces.com/problemset/problem/137/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard

AC,∑ndless 2022

Codeforces Round #177 (Div. 1) / 288A Polo the Penguin and Strings(贪心)

A. Polo the Penguin and Strings http://codeforces.com/problemset/problem/288/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output

AC,∑ndless 1932

Codeforces Beta Round #75 (Div. 2) / 92B Binary Number(贪心)

B. Binary Number http://codeforces.com/problemset/problem/92/B time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 1931

Codeforces Round #183 (Div. 1) / 303A Lucky Permutation Triple (强大的数学&想法题)

http://codeforces.com/problemset/problem/303/A when n is odd, A[i] = B[i] = i when n is even, there is no solution. why? If , then  or just , where S = 0 + 1 + ... + n - 1 = n(n - 1) / 

AC,∑ndless 1915

Codeforces Round #237 (Div. 2) / 404C Restore Graph (构造最短路径树)

http://codeforces.com/contest/404/problem/C 思路:我们构造一颗最短路径树就行了。 若能够构造,边数必然为n-1(样例1的边数可以是两条)。 如何构造?从距离为1的点开始,逐渐往下加边,生成一颗k叉树。若在中间生成了大于k的叉,则输出-1。 完整代码: /*265ms,4436KB*/ #include using namesp

AC,∑ndless 1840

Codeforces Round #186 (Div. 2) / 313B Ilya and Queries (字符串处理)

B. Ilya and Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ilya the Lion wants to help all his fri

AC,∑ndless 1810

【优化&大师级代码欣赏】Codeforces Round #137 (Div. 2) / 222B Cosmic Tables (矩阵)

B. Cosmic Tables http://codeforces.com/problemset/problem/222/B time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 1782

Codeforces Round #218 (Div. 2) / 371B Fox Dividing Cheese (想法题)

http://codeforces.com/contest/371/problem/B 神题必有神解——你能想到这么做吗? /*15ms,0KB*/ #include using namespace std; int op_cnt[6]; int main() { int a, b, ans = 0; cin >> a >> b; for (int n = 2; n <=

AC,∑ndless 1696
上一篇: Codeforces Beta Round #92 (Div. 2) / 124A The number of positions (简单数学)
下一篇: POJ 2245 Lotto (枚举)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值