Codeforces Round #336 (Div. 2) 608B Hamming Distance Sum(dp)

AscendNPU-IR面向昇腾的MLIR中间表示,提供昇腾完备表达能力 AscendNPU IR(AscendNPU Intermediate Representation)是基于MLIR(Multi-Level Intermediate Representation)构建的,面向昇腾亲和算子编译时使用的中间表示,提供昇腾完备表达能力,通过编译优化提升昇腾AI处理器计算效率,支持通过生态框架使能昇腾AI处理器与深度调优。 AscendNPU IR提供多级抽象接口:提供一系列高层抽象接口,屏蔽昇腾计算、搬运、同步指令细节,编译优化自动感知硬件架构,将硬件无关表达映射到底层指令,提升算子开发易用性;同时提供细粒度性能控制接口,能够精准控制片上内存地址、流水同步插入位置以及是否使能乒乓流水优化等,允许性能细粒度控制。 立即下载

B. Hamming Distance Sum
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Genos needs your help. He was asked to solve the following programming problem by Saitama:

The length of some string s is denoted |s|. The Hamming distance between two strings s and t of equal length is defined as , where si is the i-th character of s and ti is the i-th character of t. For example, the Hamming distance between string "0011" and string "0110" is |0 - 0| + |0 - 1| + |1 - 1| + |1 - 0| = 0 + 1 + 0 + 1 = 2.

Given two binary strings a and b, find the sum of the Hamming distances between a and all contiguous substrings of b of length |a|.

Input

The first line of the input contains binary string a (1 ≤ |a| ≤ 200 000).

The second line of the input contains binary string b (|a| ≤ |b| ≤ 200 000).

Both strings are guaranteed to consist of characters '0' and '1' only.

Output

Print a single integer — the sum of Hamming distances between a and all contiguous substrings of b of length |a|.

Sample test(s)
input
01
00111
output
3
input
0011
0110
output
2
Note

For the first sample case, there are four contiguous substrings of b of length |a|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is|0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is1 + 0 + 1 + 1 = 3.

The second sample case is described in the statement.




题目链接:点击打开链接

给出2个字符串a, b. 问字符串b中和字符串a长度相同的子串对应01不同的有多少对.

若a, b两字符串长度相同, 则直接比较. 若字符串长度不同, 记录当前位置以前所有的0, 1个数, 最后累加得到答案.

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
#include "cstdlib"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 5;
char a[MAXN], b[MAXN];
ll ans, dp0[MAXN], dp1[MAXN];
int main(int argc, char const *argv[])
{
	scanf("%s%s", a + 1, b + 1);
	int len1 = strlen(a + 1), len2 = strlen(b + 1);
	if(len1 == len2) {
		for(int i = 1; i <= len1; ++i)
			if(a[i] != b[i]) ans++;
	}
	else {
		for(int i = len2; i >= 1; --i)
			if(b[i] == '0') {
				dp0[i] = dp0[i + 1] + 1;
				dp1[i] = dp1[i + 1];
			}
			else {
				dp1[i] = dp1[i + 1] + 1;
				dp0[i] = dp0[i + 1];
			}
		for(int i = 1; i <= len1; ++i)
			if(a[i] == '0') ans += dp1[i] - dp1[len2 - len1 + i + 1];
			else ans += dp0[i] - dp0[len2 - len1 + i + 1];
	}
	printf("%lld\n", ans);
	return 0;
}


超声波熔接结构设计.pdf 技术分享 立即下载

相关推荐

高校院所评估创新战略联盟成员贡献度,有哪些量化的评价模型或工具?.docx

科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。

Codeforces Round #336 (Div. 2)B. Hamming Distance Sum

B. Hamming Distance Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Genos needs your help. He was asked

ZZ_AC的博客 755

全国范围内具备权威性的科创企业信用及画像数据服务商排名情况如何?.docx

科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。

Codeforces Round #321 (Div. 2) 580C Kefa and Park(dfs)

题目链接: 第一行给你n、m,接下来的一行有n个数,如果为1则代表这个点有cat,接下来的n-1行每行给出x、y,表示x、y相连。问你从1出发 能到达的叶子结点有几个,要求到达叶子结点的路上连续有cat的点不超过m。 a数组保存结点是否含有cat,从1这个点开始dfs,每次dfs对cat数组操作,记录连续的含有cat的点数,回溯时再判断当前结点是否满足 条件,要求结点为叶子

GKHack's Blog 2042

【FLINK+Kerberos+kafka】在华为云上 bootstrap.server使用IP的GSS initiate failed 问题处理

目前互联网上所有的资料显示都是说没有正确设置KDC之类的,但本博主实际通过java代码低版本 如使用kafka-client 0.11.0 ,2.4.0等版本手动创建kafkaconfig 或者使用华为云的LoginUtils类 都能够正常链接,所以应该是高版本添加了相关配置,或者flink在subtask 创建kafkaAdminClient时 丢弃或使用了默认的一些配置行为,导致了客户端和kdc验证之间出现了principal 不一致导致验证失败。client.dns.lookup配置项作用。

honghanyue1791的博客 580

Arduino程序设计(十)8×8 共阴极LED点阵显示(MAX7219)

本文主要介绍8×8 LED点阵显示实验,分别是:1、介绍MAX7219点阵模块;2、点阵显示部分图形;3、点阵显示数字 0~9 及 26 个英文字母。1、通过上述两个点阵实验,了解了8*8点阵显示的基本原理;2、通过SPI通信控制点阵显示,学会了Arduino用SPI通信方式控制外设。

Alice的博客 1万+

Codeforces Round #200 (Div. 2)344E Read Time(二分)

E. Read Time time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mad scientist Mike does not use slow hard disks

GKHack's Blog 1750

面试复习题--RN面试

考察点:热更新方案的深度理解,选型能力,实战落地经验。答题思路主流热更新方案对比。

hqiangtai的博客 746

Codeforces Round #325 (Div. 2) 586ABC题解

题目链接:点击打开链接 A: 给出Alena的课表, 1代表有课, 0代表没课, 2个连续0以上可以回家休息, 问你一天在学校待多久. 直接模拟即可, 可以直接计算1, 101的数目. 我记录了开头的1和结尾的1, 然后减去2个连续0以上的个数就是答案. AC代码: #include "iostream" #include "cstdio" #include "cstring" #

GKHack's Blog 1711

LCD、LED、OLED、Mini LED、Micro LED、全阵列LED、QLED、QD-OLED、QNED、AMOLED是什么意思?

LCD(液晶显示器,Liquid Crystal Display)定义:LCD 是一种利用液晶材料控制光线通过的显示技术,需依靠背光源(如冷阴极荧光灯 CCFL 或 LED)照亮液晶层以形成图像。技术原理:液晶分子在电场作用下改变排列,控制背光通过的强度和颜色。液晶本身不发光,需外部光源。特点:结构包括背光层、液晶层、彩色滤光片和偏光片。响应时间较慢,黑色表现因背光漏光而偏灰。LED(发光二极管显示,Light Emitting Diode)定义。

中国最威武的城市!武功军威-武威,铁骨铮铮! 3440

Qualcomm AI Engine Direct SDK(QNN)的使用介绍

Qualcomm AI Engine Direct SDK,高通新的AI模型推理框架,又名QNN,为AI开发提供统一API的底层框架。通过这个SDK,可以在高通的 CPU/GPU和HTP上对AI模型进行性能加速。2.Qualcomm AI Engine Direct SDK的公开英文文档。1.Qualcomm AI Engine Direct SDK的下载和安装。

u013250861的博客 6980

Codeforces Round #308 (Div. 2)题解

第二天补的 并不都是自己写的 参考了别人的题解 感觉这次cf题意好懂 就是做起来嘛。。 毕竟我还太弱。。 只为落实 A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input

GKHack's Blog 1675

智元机器人开源具身仿真框架 Genie Sim 入门教程

GenieSim是AgiBot推出的具身智能仿真框架,提供完整闭环开发管道,包括轨迹生成、模型训练和基准测试。框架支持Docker容器化部署,要求Ubuntu 22.04和NVIDIA硬件环境。主要功能涵盖: 支持12种基准测试任务 提供ADER评估框架 集成UniVLA/RDT等基线模型 支持PICO/键盘遥操作 具备轨迹记录回放功能 提供完整API控制接口 开发者可通过Hugging Face获取场景资产,使用标准化ROS主题与仿真环境交互。框架特别优化了碰撞检测和抓取物理模拟,适用于从简单抓取到复杂操

2506_90492529的博客 2551

Codeforces Round #322 (Div. 2) 581A 581B 581C

581A链接:点击打开链接 给你a只红袜子,b只蓝袜子,问你可以组成多少对颜色不同的袜子以及剩下多少对单色袜子。 小小的脑洞,答案分别为a, b最小值以及a - b绝对值的一半。 AC代码: #include "iostream" #include "cstdio" #include "cstring" #include "algorithm" using na

GKHack's Blog 1666

海德汉机床采集数据

海德汉数控系统我一般在高端机床上见得比较多。有好多五轴加工精度比较高的机床都用的是海德汉的系统。市面上常见的有530和640等型号。海德汉的采集还是有点难度的,需要对SDK有深度的了解。

若云流风的专栏 1537

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Codeforces Round #250 (Div. 2) 437C The Child and Toy(脑洞贪心)

C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output On Children's Day, the child got a toy

GKHack's Blog 1630

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Codeforces Round #313 (Div. 2) 560D Equivalent Strings(dos)

D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gera

GKHack's Blog 1619

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Codeforces Round #315 (Div. 2)569C Primes or Palindromes?(预处理)

C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that t

GKHack's Blog 1601

Codeforces Round #201 (Div. 2) 347C Alice and Bob(脑洞)

C. Alice and Bob time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It is so boring in the summer holiday, isn

GKHack's Blog 1585

Manthan, Codefest 16 633C Spy Syndrome 2(dfs + stl)

C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After observing the results of Spy Syndro

GKHack's Blog 1575

Codeforces Round #337 (Div. 2) 610D Vika and Segments(线段树)

D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vika has an infinite sheet of squared

GKHack's Blog 1533

Codeforces Round #250 (Div. 2) 437A The Child and Homework(模拟)

A. The Child and Homework time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Once upon a time a child got a tes

GKHack's Blog 1506

Codeforces Round #315 (Div. 2)569D Symmetric and Transitive(dp)

D. Symmetric and Transitive time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Little Johnny has recently le

GKHack's Blog 1503

Codeforces Round #Pi (Div. 2)567A Lineland Mail(模拟)

A. Lineland Mail time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output All cities of Lineland are located on the

GKHack's Blog 1487

Codeforces Round #332 (Div. 2) 599C Day at the Beach(脑洞)

C. Day at the Beach time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Squidward, Spongebob and Patric

GKHack's Blog 1457
上一篇: Codeforces Round #336 (Div. 2) 608D Zuma(dfs+dp)
下一篇: Codeforces Round #337 (Div. 2) 610B Vika and Squares(脑洞)
GKHack
博客等级 码龄12年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值