当前位置:网站首页>D. Mark and Lightbulbs
D. Mark and Lightbulbs
2022-07-19 09:46:00 【Vegetable newbie】
D. Mark and Lightbulbs
The question
Give you two binary strings of the same length s and t, When s[i - 1] != s[i + 1] You can flip s[i], Ask at least how many operations you can make s Flip into t, If not, output -1.
Examination site
thinking
Ideas
- about 0 0 0 1 1 1 1 0 0 0
- We combine the same into a block , namely 0 1 0
- No matter how we operate , The number of blocks does not change .
- So let's calculate
sandtNumber of blocks for , If the number of blocks is different , It's not feasible . - If possible , The contribution of each block is the absolute value of the subscript difference of the left endpoint of the block
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
char s[N], t[N];
int n;
void solve(){
scanf("%d",&n);
scanf("%s", s + 1);
scanf("%s", t + 1);
vector<int>a, b;
for(int i = 1; i <= n; i ++ ){
if(s[i] != s[i - 1]) a.push_back(i);
if(t[i] != t[i - 1]) b.push_back(i);
}
if(s[1] != t[1] || s[n] != t[n] || a.size() != b.size()) puts("-1");
else{
long long ans = 0;
int len = a.size();
for(int i = 0; i < len; i ++ ) ans += abs(a[i] - b[i]);
printf("%lld\n", ans);
}
}
int main(){
int tt;
scanf("%d",&tt);
while(tt -- ){
solve();
}
return 0;
}
边栏推荐
- Programmer growth Article 21: when assigning tasks, we should consider the growth of employees.
- 代码庆端午--粽你心意
- LDA classifier
- pytorch 调用 cublasLtMatmul 做 gemm同时加bias的代码,写的不错
- 第一部分—C语言基础篇_1. C语言概述
- idea卡顿且报错:UI was frozen for xxxxx ms问题解决
- Rhcsa jour 2 7,15
- 【C语言】整形数据的存储
- Series operation of vector container (detailed explanation)
- 第八章 STL 之 vector
猜你喜欢

Anaconda与Jupyter Notebook入门级详细使用教程

Questions d'entrevue - concevoir des cas d'essai pour:: memcpy

第一部分—C语言基础篇_6. 函数
![[C language] Pointer exercise 2 - real written test questions and analysis](/img/fb/ce6cf718f2ef1a498f82ed29c4e751.png)
[C language] Pointer exercise 2 - real written test questions and analysis

【ACWing】947. text editor

Fundamentals of C language -- 2-1 pointer and wild pointer

第4章-一阶多智体系统一致性 -> 连续时间含时延系统一致性

rhcsa 第一天 7.11

MySQL -- SQL optimization case -- implicit character encoding conversion

DuiLib 实现tooltip自定义鼠标提示窗口
随机推荐
程序员成长第二十一篇:做任务分配时,要考虑员工的成长。
Fundamentals of C language -- 2-2 const keywords and pointers
第4章-一阶多智体系统一致性 -> 连续时间含时延系统一致性
[C language] storage of shaping data
[C language] storage of floating-point type in memory
一汽丰田亚洲狮首次产品焕新
光辉使用输出
Programmer growth Article 21: when assigning tasks, we should consider the growth of employees.
R语言data.table导入数据实战:data.table使用dcast.data.table函数实现透视表(pivot table)
企业数字化转型,为何 SaaS 模式如此重要?
Part I - Fundamentals of C language_ 6. Function
C语言基础篇 —— 2-2 const关键字与指针
Chapter VIII vector of STL
18、shell脚本编程(1)
【C语言】数组知识点总结
Add - before the command in makefile to ignore the error caused by the command and continue to execute the next command
[performance optimization methodology series] VI. summary
多租户 SaaS 的数据库设计模式,你学废了吗?
pytorch 调用 cublasLtMatmul 做 gemm同时加bias的代码,写的不错
mysql进阶(六)模糊查询的四种常见用法介绍