CodeForces 165C - Another Problem on Strings

用limma包进行多组差异表达分析 写在前面:最近在使用limma包进行差异表达分析,参考了网上许多教程都觉得说的云里雾里,很不清楚。经过我自己一段时间非常痛苦的钻研,弄明白了,解决了我的实际需求。于是决定将我的分析经验写下来,分享给需要的人。 首先加载前期预处理好的表达矩阵。(我的原始表达矩阵文件已附在文后,大家有需要可以下载实践) setwd("E://Rworkplace") data<-read.table... 阅读详情

C. Another Problem on Strings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A string is binary, if it consists only of characters "0" and "1".

String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their positions of occurrence are different. So, if some string occurs multiple times, we should consider it the number of times it occurs.

You are given a binary string s. Your task is to find the number of its substrings, containing exactly k characters "1".

Input

The first line contains the single integer k (0 ≤ k ≤ 106). The second line contains a non-empty binary string s. The length of s does not exceed 106 characters.

Output

Print the single number — the number of substrings of the given string, containing exactly k characters "1".

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64dspecifier.

Sample test(s)
input
1
1010
output
6
input
2
01010
output
4
input
100
01010
output
0
Note

In the first sample the sought substrings are: "1", "1", "10", "01", "10", "010".

In the second sample the sought substrings are: "101", "0101", "1010", "01010".



===============================

找含k个1的子串有多少个


自己做了好久,一直都有没考虑到的情况orz看别人都是几分钟就A了于是学习了下别人的方法……看了半天才看懂orz

要注意最后的答案可能会超过int

strlen()不能直接放进循环里否则会超时


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
long long num[1111111];
char str[1111111];

int main()
{
    int k,cnt=0;long long ans=0;
    scanf("%d",&k);
    scanf("%s",str);
    num[0]=1;
    int len=strlen(str);
    for(int i=0;i<len;i++)
    {
        if(str[i]=='1') cnt++;//1的个数
        if(cnt>=k) ans+=num[cnt-k];//截止到第i位,第 cnt-k 个1前面有几个0答案就有几种可能
        num[cnt]++;//第cnt个1前面的0的个数(cnt从0开始)
    }
    printf("%I64d\n",ans);
    return 0;
}


基于STM32的工业设备状态监测系统 工业设备的预测性维护需求日益增长,本文设计了一款基于STM32的智能监测终端,可实时采集设备振动、温度、电流等关键参数,通过边缘计算分析设备健康状态,实现故障预警与能效优化。系统支持4G/LoRa远程通信,适用于工厂、发电站等工业场景。本系统实现了工业设备关键参数的实时监测,故障识别准确率达到92%。:STM32F429(带FPU,支持浮点运算)多参数联合判据(振动+温度+电流突变检测)ACS712电流检测模块(0-30A)FFT频谱分析(识别轴承故障特征频率)故障代码生成(支持16种预设故障类型) 阅读详情

相关推荐

Win11网络卡顿?用Wireshark抓包5分钟定位问题(保姆级实战)

本文详细介绍了如何使用Wireshark在Win11系统中快速定位网络卡顿问题。通过5分钟抓包分析,作者成功发现TCP重传率高达37%的罪魁祸首,并提供了从准备工作到实战分析的保姆级教程,帮助用户解决游戏卡顿、视频会议延迟等常见网络问题。

weixin_28839629的博客 315

codeForces 165C.Another Problem on Strings (二分+前缀和)

题意:给你一个整数K和一个只含01的字符串s,问你在这个字符串s中有多少个含有k个‘1’的子串。 思路:k和字符串长度都为10^6,所以暴力枚举所有子串不行,我们可先求一个前缀和统计到当前位置有多少个1,这样我们每次只需要用O(1)的负责度就可以知道任意两个位置之间(也就是某个子串中)有多少个‘1’了,然后我们枚举子串起点i,然后对于每一个起点寻找sum[i] + k - (s[i] - '0'

张松超的博客 682

Arm A-profile架构RAS系统设计:可靠性、可用性与可服务性解析

在计算机体系结构中,可靠性(Reliability)、可用性(Availability)和可服务性(Serviceability)是构建高可信系统的核心要素。RAS系统通过硬件错误检测、隔离和恢复机制,确保系统持续稳定运行。其技术原理包括ECC内存纠错、冗余执行单元和错误传播阻断等关键技术,可显著降低数据中心等关键业务场景的故障率。现代芯片设计中,Arm A-profile架构提供标准化的RAS框架,涵盖从内存子系统到计算单元的全方位错误管理。通过分层防御策略和统一错误记录格式,实现硬件错误可追溯、可修复。

weixin_30920853的博客 369

CodeForces 165C - Another Problem on Strings(思路)

题意:给定一个长度为 n (1 <= n <= 10^6 ) 的01串,求有多少连续子序列中包含 k 个 1。 从前往后记录到第 i 个元素存在了多少个 1,然后从前往后找个数 >= k 的元素,再找 - k 与 - k + 1 之间与多少个元素加入结果即可。 #include<cstdio> #include<cstring&gt...

dingyaosao9792的博客 156

HEVC/VVC中R-Lambda码率控制算法原理

文章目录1. 比特分配1.1 GOP级比特分配1.2 帧级比特分配1.3 LCU级比特分配2. 码率控制2.1 λ的计算和更新2.2 参数QP的确定 VVC中码率控制算法沿用了HEVC中经典的R-λ码率控制模型,R-λ由中科大的李斌博士提出(详情参考JCTVC-K0103)。R-λ模型的基础为视频编码中 R(比特 bpp)和 D(失真 MSE)之间的双曲线模型,即 D(R)=CR−KD(R) = ...

Aidoneus_y 6144

SAP资产按每天折旧功能介绍

注意:此处在计算百分比时将30天作为剩余使用寿命,因为SAPS/4HANA中的计算是通过考虑购置第一年的折旧总天数来进行的。这是因为我在计算总使用寿命时只使用了365天,如果剩余使用寿命大于1年,SAPS/4HANA会将闰年规范化为365天。此功能仅对确定使用寿命或剩余寿命百分比的折旧键有用,如果需要,这种折旧到日的解决方案可以应用于需要每天计算折旧的跨行业(任何国家/行业)。注意:这里在计算百分比时考虑了2天,因为364天已经过期,但目前我们到达2024年,使用寿命为366天。它只会在下一年生效。

yanzibing99的博客 1574

Another Problem on Strings

本题中‘0’不起计数作用,但对排列有影响 当k==1时 对数组进行for循环 从第一位开始遍历 到满足k个1为止,统计整体前后0的个数 k==1 例如:1010 第一个1产生的影响(1 10) 第二个1产生的影响(01 010 1 10) 1前面的0(包括1)记为x,后面的(1和0的个数)记为y //1*2 //2*2 再...

C_Dreamy的博客 763

OpenOCD入门到精通:第28章 综合实战:RISC-V 调试

RISC-V调试实战摘要 本文介绍了RISC-V调试规范及其在OpenOCD中的实现。主要内容包括: RISC-V Debug规范的两个版本(0.11和0.13)及其差异,OpenOCD通过自动检测DTMCS寄存器版本号选择对应驱动实现。 RISC-V调试架构的分层设计,包含DTM、Debug Module、Program Buffer等核心组件,以及三种内存访问方式(progbuf、sysbus、abstract)。 以GD32VF103为例的实战调试配置,包括硬件连接、OpenOCD配置文件编写和GDB

从事嵌入式linux android驱动开发,拥有全栈能力 289

Another Problem on Strings(sdau19训练)

【Question】 A string is binary, if it consists only of characters “0” and “1”. String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. ...

qq_45949914的博客 301

【DEIM创新改进】 独家创新首发、注意力改进篇 | CVPR2025 | DEIM模型引入分层多头注意力 (HMHA) 机制, 从而捕获更具多样性的特征,含多种不同基准改进点,助力目标检测有效涨点

本文提出了一种基于分层多头注意力(HMHA)的改进DEIM网络模型。HMHA通过重排序和分层子空间划分使注意力头学习多样化特征,并结合查询-键缓存更新(QKCU)机制增强注意力头之间的交互。该方法包含HMHA和QKCU两个模块,有效解决了传统多头注意力(MHA)的冗余问题。文章详细介绍了HMHA模块的结构、优势及核心代码实现,并提供了改进模块的添加步骤和配置文件示例。该改进方案能有效提升特征多样性,增强头间交互性,提高模型可解释性,适用于各种计算机视觉复杂场景任务。

Ai缝合怪、助力小伙伴高效发论文 266

DeepLabv3+改进专栏

🔥【DeepLabv3+改进专栏!探索语义分割新高度】🌟 你是否在为图像分割的精度与效率发愁?📢 本专栏重磅推出:✅ 独家改进策略:融合注意力机制、轻量化设计与多尺度优化✅ 即插即用模块:ASPP+升级、解码器。

AIcurator的博客 2582

Codeforces 165C Another Problem on Strings 【二分】

题目链接:Codeforces 165C Another Problem on Strings C. Another Problem on Strings time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A string i

世界很大 1301

36、T5L 迪文屏C51开发之绘制动态曲线

T5L 迪文屏C51开发之绘制动态曲线1、介绍2、例程功能简介3、GUI界面设计3、C51程序设计 1、介绍   本文将利用DGUS Tool软件中的【动态曲线控件】来绘制曲线效果,在T5L迪文屏中总共支持8个通道的曲线,而曲线数据是需要缓冲区的,如果 8 通道曲线同时使用,0x1000-0x4FFF 将作为曲线缓冲区地址,此时该部分变量地址不能被其他控键使用,其他控键地址使用范围为0x5000-0xFFFF,当某曲线通道不被使用时,那么其所对应的缓冲区地址可以做其他用途,曲线通道具体的地址分布如下图所示:

嵌入式羊圈 3144

Codeforces 165C Another Problem on Strings(尺取法)

题目 题目链接Problem - 165C - Codeforces C. Another Problem on Strings 2 seconds 256 megabytes A string isbinary, if it consists only of characters "0" and "1". Stringvis asubstringof stringwif it has a non-zero length and can be read sta...

Carry_hkr的博客 368

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

codeforces-165C-Another Problem on Strings

C. Another Problem on Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A string is binary, if it consists only of characte

看起来喜欢做枯燥事情的人或许只是更清楚自己想要什么罢了 585

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Another Problem on Strings CodeForces - 165C

Another Problem on Strings CodeForces - 165C A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can b

codeswarrior的博客 446

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

CodeForces - 165C Another Problem on Strings (前缀)

题目链接:http://codeforces.com/problemset/problem/165/C点击打开链接 C. Another Problem on Strings time limit per test 2 seconds memory limit per test 256 megabytes input standar

xuejye的博客 664

CodeForces 165C Another Problem on Strings(组合)

A string isbinary, if it consists only of characters "0" and "1". Stringvis asubstringof stringwif it has a non-zero length and can be read starting from some position in stringw. Fo...

apk6909的博客 130

Another Problem on Strings-(CodeForces-165C)

*C. Another Problem on Strings* time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A string is binary, if it consists only of characters “...

lvy_yu_ET的博客 358

CodeForces 165C Another Problem on Strings(公式推导)

A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "

HJY 580

codeforces 165C Another Problem on Strings 双指针

题意:求对于给定01字符串,有多少个子串,其恰好包含了k个1 双指针,把每个1都找出来,统计这个1之后有多少个0 然后用乘法原理计算 #include #include #include #include #define rep(i, j, k) for(int i = j; i <= k; i++) using namespace std; typedef long

cadongllas的博客 404

CodeForces 165C Another Problem on Strings

Another Problem on Strings A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from so

galesaur_wcy 523

CodeForces 165C Another Problem on Strings

A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For examp

CS33sun的博客 361

Codeforces 165C Another Problem On Strings 尺取 Or 前缀和

点击打开链接 题意:给出串s,长度 尺取:以l为左端点成立的子串,若第一次在r成立 最后一次在y成立(r后的第一个1在y+1) 则个数为y-r+1 第一次在r成立,[l,r]成立 [l+1,r-1]肯定不成立  dp记录i后的第一个1 复杂都为O(2*n) #include using namespace std; typedef long long ll; const int

Masamiiiiii 431

CodeForces - 165C Another Problem on Strings 前缀和+二分

题意: 给定一个01串和k,求包含k个1的子串的个数 思路: 用前缀和记录到当前位置的个数,那么就可以知道某个子串的1的个数 我们遍历字符串 对于每个位置i,以他为开头的子串,要求1的个数为k的数量,我们只需要求有多少个值等于sum[i-1]+k就可以了, 枚举肯定不行,因为是前缀和有序,我们二分,两次二分 upper_bound(sum+1,sum+len+1+1,sum[i-1]+k)-low...

青春苦瓜 325

CodeForces 165C Another Problem on Strings(递推)

题意:给出一个二进制串,统计有多少中含有k个一的子串。 思路:令答案为ans,首先用数组a记录1出现的位置,用cnt代表a的个数,当1的个数大于等于k时,ans += a[cnt - k - 1] - a[cnt - k] ;  注意:当k = 0时,特判。 #include #include #include #include #include #include #include #

fly_tzf的博客 639
上一篇: CodeForces 155B - Combination(贪心)
下一篇: CodeForces 160B - Unlucky Ticket
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值