题目链接

题目大意:

给你两个字符串只有01组成,你可以选取区间[l, r],对字符串a在区间里面进行异或操作,对字符串b非区间值进行异或操作,问能否将两个字符串变为全0串。如果可以输出YES, 操作次数, 操作区间。

思路:

将他们全部变成0,等价于将全0变成a, b串。经归纳法可以发现,在进行基数次操作后a,b串每个对应字符都不同,偶数次操作他们每个对应字符都相同。那么我们可以进行的操作方案是将a串上的1全部变为0,如果b[1]=1,那代表b串全部是1,a串全部为0,那么我们可以进行操作(1,1),(1, 2),(2,2)。这样就结束了。

注意:

cout << endl; //速度很慢,不推荐使用
ios :: sync_with_stdio(false);
cin.tie(0);
cout.tie(0); //使用该流解除后将不能使用puts(""), 和scanf(), printf();

AC代码:

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i <= (k); --i)
#define ll long long
#define sz(a) ((int) (a).size())
#define vi vector< int >
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
#define ld __float128 using namespace std; const int N = 1e6 + 7;
int n, m, t;
char s[N], p[N];
int a[N], b[N];
void Main() {
cin >> n;
cin >> (s + 1) >> (p + 1);
for (int i = 1; i <= n; i ++ ) {
a[i] = s[i] - '0';
b[i] = p[i] - '0';
}
for (int i = 1; i <= n; i ++ ) {
b[i] ^= a[i];
if (b[i] != b[1]) {
cout << "NO\n";
return ;
}
}
vector< pair<int, int> > vc;
for (int i = 1; i <= n; i ++ ) {
if (a[i]) {
vc.emplace_back(i, i);
b[1] ^= 1;
}
} if (b[1]) {
vc.emplace_back(1, 1);
vc.emplace_back(1, 2);
vc.emplace_back(2, 2);
}
cout << "YES\n";
cout << sz(vc) << '\n';
for (auto i : vc)
cout << i.first << ' ' << i.second << '\n';
} int main() {
ios :: sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) Main();
return 0;
} /* stuff you should look for 你应该寻找的东西
* int overflow, array bounds (int)溢出,数组边界
* special cases (n=1?) 特殊情况(n=1?)
* do smth instead of nothing and stay organized 做一些事情而不是什么也不做,保证效率
* WRITE STUFF DOWN 将东西写下
* DON'T GET STUCK ON ONE APPROACH 不要在一个地方死磕
*/

Complementary XOR的更多相关文章

  1. CodeTON Round 3 (C.差分维护,D.容斥原理)

    C. Complementary XOR 题目大意: 给你两个01串ab,问你是否可以通过一下两种操作在不超过n+5次的前提下将两个串都变为0,同时需要输出可以的操作方案 选择一个区间[l,r] 将串 ...

  2. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  3. 二分+DP+Trie HDOJ 5715 XOR 游戏

    题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  4. BZOJ 2115 【Wc2011】 Xor

    Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...

  5. xor和gates的专杀脚本

    前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor. 首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xo ...

  6. Codeforces617 E . XOR and Favorite Number(莫队算法)

    XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...

  7. Xor && 线性基练习

    #include <cstdio> #include <cstring> ; ; int cnt,Ans,b,x,n; inline int Max(int x,int y) ...

  8. BC之Claris and XOR

    http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...

  9. 异或链表(XOR linked list)

    异或链表(Xor Linked List)也是一种链式存储结构,它可以降低空间复杂度达到和双向链表一样目的,任何一个节点可以方便的访问它的前驱节点和后继结点.可以参阅wiki 普通的双向链表 clas ...

  10. hdu 5661 Claris and XOR

    Claris and XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. Nginx_Mac安装时使用

    Mac 上安装和使用Nginx 1. 安装Nginx brew install nginx 2. 启动Nginx nginx 其他命令 重启Nginx nginx -s reload 关闭(停止)Ng ...

  2. flutter系列之:flutter中常用的GridView layout详解

    目录 简介 GridView详解 GridView的构造函数 GridView的使用 总结 简介 GridView是一个网格化的布局,如果在填充的过程中子组件超出了展示的范围的时候,那么GridVie ...

  3. harbor官方关于创建https的有关命令

    官方地址:https://goharbor.io/docs/2.0.0/install-config/configure-https/ 命令总结: openssl genrsa -out ca.key ...

  4. Kubernetes DevOps: Jenkins Pipeline (流水线)

    要实现在 Jenkins 中的构建工作,可以有多种方式,我们这里采用比较常用的 Pipeline 这种方式.Pipeline,简单来说,就是一套运行在 Jenkins 上的工作流框架,将原来独立运行于 ...

  5. 内网部署YApi

    官网地址:https://hellosean1025.github.io/yapi/devops/index.html 环境要求 nodejs(7.6+) mongodb(2.6+),安装看这篇文章: ...

  6. Docker安装集群rabbitMQ

    环境准备 Centos 7.5虚拟机三台: 192.168.102.128 192.168.102.130 192.168.102.131 以上虚拟机统一安装docker环境 三台机器分别配置如下所示 ...

  7. 初试 Prometheus + Grafana 监控系统搭建并监控 Mysql

    转载自:https://cloud.tencent.com/developer/article/1433280 文章目录1.Prometheus & Grafana 介绍1.1.Prometh ...

  8. NSIS皮肤插件:vcl-styles-plugins

    vcl-styles-plugins简介   NSISVCLStyles  plugin (dll)是一款应用于nsis安装程序的皮肤插件,插件大小约为1.6MB,实际应用在安装程序中压缩后约为550 ...

  9. JavaScript根据参数获取url中参数名的值

    //假设ulr如下var localhost="http://127.0.0.1?name=tom&sex=男&id=1";//正则方法封装function Get ...

  10. DevOps|高效能敏捷交付组织:特性团队(FeatureTeam)+Scrum

    这是<研发效能组织能力建设>的第三篇.特性团队和Scrum,这两个定义我们在之前的文章中都详细介绍了.这两个组织模式或者说管理实践,我都用过所以有些时候特别有感触.书本上纯粹的模式很容易理 ...