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

嵌入式笔试面试题库 250 题|13 章从 C 语言到 FreeRTOS,每题带追问 面试里有两类问题。第一类问「static 有几个作用」,第二类问「串口丢数据你怎么查」。第一类决定你能不能进二面,第二类决定二面之后还有没有下文。 这份合并版 250 题、13 章,把上篇与下篇收在一本: · 上篇 130 题(一至六章):单片机与体系结构、C 语言关键字、指针与内存、位运算与寄存器、中断与并发、编译链接与内存布局; · 下篇 120 题(七至十三章):GPIO 与时钟、定时器与 ADC、串口 I2C SPI、DMA 与中断、FreeRTOS、通信协议与总线、项目与工程实践。 每题结构一致:一段分点参考答案(①②③ 给要点骨架),紧跟一条追问,写明面试官往下会挖哪一层。答案尽量落到三层——现象、根因、验证方法。比如「PWM 出不来波形」,不只列六项检查顺序,还说清为什么 TIM1 容易漏掉 MOE 这一位、怎么用示波器确认。 三个附录:A 是 40 天复习路线(每天 40 分钟,标每天题量与当章重点);B 是十三章自测评分表(现象 / 根因 / 验证三列打分);C 是按现象查题的排障索引,遇到具体问题直接定位到题号。 交付:Word 可编辑版 + PDF 打印版(A4 / 70 页)+ 使用说明。题号连续 Q001–Q250,目录与附录各一套,跨篇追问能顺着查。 说明:寄存器位定义与分频关系按 STM32F103 系列整理,换 F4/F7/G0 需按对应手册核对;FreeRTOS 部分按 10.x 之后接口描述。题库不替代动手调试。 立即下载

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;
}


政府科技管理者如何提升科技成果评估的准确性与透明度?.docx 政府科技管理者如何提升科技成果评估的准确性与透明度? 立即下载

相关推荐

双闭环PWM整流器VOC控制 +SVPWM调制仿真(Simulink仿真实现)

内容概要:本文详细介绍了基于Simulink平台构建的双闭环PWM整流器VOC(虚拟磁链定向控制)与SVPWM(空间矢量脉宽调制)相结合的仿真模型,系统阐述了三相电压型PWM整流器在电压定向控制策略下的建模方法与控制实现。通过设计外环直流电压控制与内环电流控制的双闭环结构,实现了对整流器的高功率因数运行、能量双向流动及动态性能优化的精确调控。结合SVPWM调制技术,有效提升了直流侧电压利用率并显著降低输出电流谐波含量,增强了系统的整体效率与稳定性。该仿真模型适用于新能源发电、电动汽车充电系统、微电网等高性能电能变换应用场景,文档还配套提供了丰富的学习资源与技术支持渠道,便于深入研究与工程实践。; 适合人群:面向电气工程、自动化、电力电子及相关专业的高校学生、科研人员以及从事新能源、智能电网、电力传动等领域研发工作的工程师;尤其适合已具备自动控制理论、电力电子变换技术和MATLAB/Simulink仿真基础的专业人士进一步深化学习与应用。; 使用场景及目标:①深入理解PWM整流器的工作机理及其双闭环控制系统的架构设计;②掌握VOC控制与SVPWM调制的协同工作机制,提升系统动静态响应性能;③支撑科研课题、课程设计、毕业设计或实际工程项目中的整流器控制系统开发与验证;④作为高级电能变换技术的学习范例,促进对现代电力电子系统控制策略的综合理解与创新能力培养。; 阅读建议:建议结合文中提供的百度网盘链接与公众号资源,下载完整的Simulink仿真模型进行实操演练,在MATLAB环境中调整控制器参数并观察仿真结果,深入剖析控制逻辑与系统响应特性;同时可参考同系列资源如PI双闭环控制、电网不平衡工况下的控制策略等案例,开展对比分析与拓展研究,全面提升系统建模与控制设计的综合能力。

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

两路半桥LLC谐振变换器软开关Simulink仿真(模拟谐振参数不同、分裂电容)

内容概要:本文围绕两路半桥LLC谐振变换器的软开关技术展开,基于Simulink平台构建了详细的仿真模型,重点研究了不同谐振参数(如谐振电感、谐振电容)以及分裂电容结构对系统性能的影响。通过开环与闭环控制策略的对比分析,探讨了变换器在启动过程中的动态响应特性与稳定性,并实现了软启动设计,有效降低了启动冲击。仿真内容涵盖谐振腔的工作模态、ZVS(零电压开关)与ZCS(零电流开关)的实现条件,以及分裂电容对电压均衡和效率的优化作用,全面展示了LLC变换器在高频高效电源中的应用潜力。; 适合人群:电力电子、电气工程及相关专业的高校研究生、科研人员及从事开关电源设计的工程技术人员。; 使用场景及目标:①用于深入理解LLC谐振变换器的工作原理与软开关实现机制;②为高频高效率DC-DC变换器的研发提供仿真验证平台;③支撑科研项目中的拓扑优化与控制算法设计,尤其适用于需要分裂电容结构提升性能的场合。; 阅读建议:建议结合电力电子基础理论,先掌握LLC谐振变换器的基本工作模态,再逐步深入仿真模型细节,重点关注参数扫描与闭环动态响应的仿真结果,以实现理论与实践的有效结合。

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 2041

瑞芯微rk3568移植openbmc(一)----关于ob移植的优缺点

基于rock3a的单板,CPU为瑞芯微rk3568的环境,移植了openbmc

feixiang3839的专栏 5537

电流采样电路设计:差分放大与ADC采集详解

在电机控制、电源管理、电池监测等应用中,电流采样是一个关键环节。通常,我们使用小阻值的采样电阻将电流信号转换为电压信号,再通过运放放大后送入ADC进行采集。本文将详细分析一种基于差分放大器的电流采样电路,包括信号放大、参考电压偏置、滤波保护以及ADC转换计算等内容。

W0s477的博客 2万+

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 1749

RK3568(buildroot)利用squashfs+overlay实现嵌入式系统高可靠存储方案

本文详细介绍了在RK3568嵌入式平台上,基于Buildroot系统,利用squashfs只读根文件系统与overlayfs可写层相结合的高可靠存储方案。该方案能有效防止设备意外断电导致的系统文件损坏,通过内核配置、启动脚本编写及镜像制作,实现系统核心的只读保护与用户数据的持久化分离,显著提升嵌入式设备的现场稳定性。

weixin_29189381的博客 547

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

Android开发者必看:F2FS文件系统如何优化你的手机存储性能(附实测数据对比)

本文深入解析了F2FS文件系统如何针对闪存特性优化Android设备存储性能。通过对比ext4,F2FS采用追加写和冷热数据分离策略,将随机写转化为顺序写,显著提升写入速度并减少GC卡顿。实测数据显示,其在随机写入和SQLite事务等场景下性能提升显著,为开发者提供了优化应用IO性能的关键思路。

weixin_29248313的博客 325

ROS基础(一)——命令行代码(以小乌龟程序为例)

ROS学习(一)——命令行代码(以小乌龟程序为例)1 基础命令行语句1.1 roscore1.2 rqt_graph(显示系统计算图)1.3 rosnode(显示所有节点相关信息)1.4 rostopic(和话题相关)2 服务类型指令rosservice同时存在两只海龟3 指令记录 1 基础命令行语句 从大二四旋翼无人机编队后就没再接触过ROS了,最近由于科研任务需要重新捡起来,打算系统学一下!学习过程参考古月居老师的视频,有兴趣的同学可以去[BliBli]学习。 学习平台:Ubuntu 18.04 硬件

北理自动化小白 6263

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 1674

C#WPF常用的9种布局方式详解

本文介绍WPF中常用的九种布局,Grid、StackPanel、WrapPanel、DockPanel、UniformGrid、Canvas、ScrollViewer、ViewBox、Border。

qq_30725967的博客 1万+

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 1665

web渗透学习手册

依据多年的渗透测试项目经验及个人理解,对漏洞分类

渗透之路,攻防之间皆学问 1万+

23种设计模式-享元(Flyweight)设计模式

软考中级-软件设计师 享元设计模式

片言可决讼,半纸能缚龙 3223

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 1626

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

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 1616

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

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 1599

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

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 1584

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 1574

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 1531

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 1504

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 1501

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 1485

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

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值