Codeforces Round 869 Div.1 A. Almost Increasing Subsequence 题解

邮件伪造和SPF 之前看了下邮件伪造觉得挺有意思的,所以看了下邮件伪造的东西,下面简单的总结了一下,如果有不妥的地方还望大佬们提出来。 1. 什么是SPF SPF是 Sender Policy Framework 的缩写,一种以IP地址认证电子邮件发件人身份的技术,是为了防范垃圾邮件而提出来的一种DNS记录类型,它是一种TXT类型的记录。 接收邮件方会首先检查域名的SPF记录,来确定发件人的IP地址是否被包含在SP... 阅读详情

Almost Increasing Subsequence

题面描述

给定长度为 n n n 的一个序列 a a a 以及 q q q 次询问,每次询问给出 l l l 和 r r r,找出序列 a a a 在 [ l , r ] [l,r] [l,r] 内最长的几乎递增子序列,并输出其长度。

几乎递增的定义:如果一个序列中不存在连续的三个数 x x x, y y y, z z z,使得 x ≥ y ≥   z x \ge y \ge \ z x≥y≥ z,则这个序列是几乎递增的。

输入格式

The first line of input contains two integers, n n n and q q q ( 1 ≤ n , q ≤ 200   000 1 \leq n, q \leq 200\,000 1≤n,q≤200000) — the length of the array a a a and the number of queries.

The second line contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1​,a2​,…,an​ ( 1 ≤ a i ≤ 1 0 9 1 \leq a_i \leq 10^9 1≤ai​≤109) — the values of the array a a a.

Each of the next q q q lines contains the description of a query. Each line contains two integers l l l and r r r ( 1 ≤ l ≤ r ≤ n 1 \leq l \leq r \leq n 1≤l≤r≤n) — the query is about the subarray a l , a l + 1 , … , a r a_l, a_{l+1}, \dots, a_r al​,al+1​,…,ar​.

输出格式

For each of the q q q queries, print a line containing the length of the longest almost-increasing subsequence of the subarray a l , a l + 1 , … , a r a_l, a_{l+1}, \dots, a_r al​,al+1​,…,ar​.

样例 #1

样例输入 #1

9 8
1 2 4 3 3 5 6 2 1
1 3
1 4
2 5
6 6
3 7
7 8
1 8
8 8

样例输出 #1

3
4
3
1
4
2
7
1

提示

In the first query, the subarray is a 1 , a 2 , a 3 = [ 1 , 2 , 4 ] a_1, a_2, a_3 = [1,2,4] a1​,a2​,a3​=[1,2,4]. The whole subarray is almost-increasing, so the answer is 3 3 3.

In the second query, the subarray is a 1 , a 2 , a 3 , a 4 = [ 1 , 2 , 4 , 3 ] a_1, a_2, a_3,a_4 = [1,2,4,3] a1​,a2​,a3​,a4​=[1,2,4,3]. The whole subarray is a almost-increasing, because there are no three consecutive elements such that x ≥ y ≥ z x \geq y \geq z x≥y≥z. So the answer is 4 4 4.

In the third query, the subarray is a 2 , a 3 , a 4 , a 5 = [ 2 , 4 , 3 , 3 ] a_2, a_3, a_4, a_5 = [2, 4, 3, 3] a2​,a3​,a4​,a5​=[2,4,3,3]. The whole subarray is not almost-increasing, because the last three elements satisfy 4 ≥ 3 ≥ 3 4 \geq 3 \geq 3 4≥3≥3. An almost-increasing subsequence of length 3 3 3 can be found (for example taking a 2 , a 3 , a 5 = [ 2 , 4 , 3 ] a_2,a_3,a_5 = [2,4,3] a2​,a3​,a5​=[2,4,3] ). So the answer is 3 3 3.

链接

洛谷——传送门

思路

  • 根据题意,几乎递增的序列不包含三个连续元素构成非递增序列。
  • 那么问题可以转化为找出给定数组中所有的非递增子数组,其中非递增子数组的长度>2的是不满足条件的。
  • 因此当非递增子数组长度大于2时,只取其首元素和尾元素,去掉内部元素。
  • 那么我们可以维护1到i区间内的不满足条件的内部元素个数d[i]。
  • 当查询区间答案时,只需用d[r]减去d[l+1]就是该区间内不满足条件的内部元素个数。
  • 那么一个区间的答案即为区间长度len-(d[r]-d[l+1])。
  • 至于为什么是d[r]-d[l+1]而不是d[r]-d[l-1],下面给出解释:
  • 因为不满足条件的内部元素被统计在内的前提条件是至少包含三个元素。
  • 而区间l到r中,位置l和l+1的元素前面只有零个/一个元素,加起来达不到三个元素。
  • 即预处理时在位置l和位置l+1统计的数量在该l,r区间中实际不应当计算在内。
  • 因此减去的应当是d[l+1]而非d[l-1]。
  • 另外需要注意的是:
  • l与r相等时,不存在l+1位置,则len-(d[r]-d[l+1])公式不适用,应改为len-(d[r]-d[l])。
  • 我一开始就是因为没特判WA了一发。

代码

#include <bits/stdc++.h>
using namespace std;
#define max_Heap(x) priority_queue<x, vector<x>, less<x>>
#define min_Heap(x) priority_queue<x, vector<x>, greater<x>>
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
const double PI = acos(-1);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    vector<int> d(n + 1, 0);
    // 预处理1到i区间内的不满足条件的内部元素个数d[i]
    for (int i = 3; i <= n; i++)
    {
        if (a[i - 2] >= a[i - 1] && a[i - 1] >= a[i]) // 存在不满足条件的内部元素时
        {
            d[i] = d[i - 1] + 1;
        }
        else // 继承
        {
            d[i] = d[i - 1];
        }
    }
    int l, r, len;
    while (q--)
    {
        cin >> l >> r;
        len = r - l + 1;
        if (len == 1) // 需特判len==1,因为l和r相等时l+1>r,因此不符合
            cout << len - (d[r] - d[l]) << '\n';
        // 当然,此时d[r]-d[l]等于0,因此写成cout << 1 << '\n'也是OK的
        else
            cout << len - (d[r] - d[l + 1]) << '\n';
    }

    return 0;
}
第01章 Hermes Agent 是什么 如果读者所在的开发团队已经引入了 Cursor、Claude Code 这类 AI IDE,可能会有一个困惑:写代码已经有 AI 帮忙了,还需要 Hermes Agent 做什么?这一章将给出答案。Hermes Agent 不是另一个写代码的 AI,而是一个常驻在团队里的"AI 协作成员",专门负责写代码之外的协作环节——讨论需求、审查代码、查日志、监控告警、生成报告。学完本章,读者将清楚 Hermes 的定位以及它在团队里的角色。 阅读详情

相关推荐

[信号与系统]一阶与二阶连续时间系统和离散时间系统

定义:一阶连续时间系统由一阶线性常系数微分方程描述: dy(t)dt+ay(t)=bx(t) \frac{dy(t)}{dt} + a y(t) = b x(t) dtdy(t)​+ay(t)=bx(t)时间常数:时间常数 τ=1a\tau = \frac{1}{a}τ=a1​ 是系统响应速度的衡量指标。时间常数越小,系统响应越快。冲激响应:一阶系统的冲激响应是指数衰减或增长的形式。例如,对于一个单位冲激输入,响应为: h(t)=bae−at h(t) = \frac{b}{a} e^{-at} h(t)=

Andius的博客 2121

Codeforces Round 869 (Div. 2) 题解

Codeforces Round 869 (Div. 2) 题解 A. Politics B. Indivisible C. Almost Increasing Subsequence D. Fish Graph E. Similar Polynomials F. Toy Machine

qq_73635134的博客 1602

深入解析TI C2000 ePWM模块:峰值电流模式Buck与LLC谐振变换器实战配置

脉宽调制(PWM)技术是电力电子与数字电源控制的核心,它通过调节开关信号的占空比或频率,实现对功率变换器输出电压、电流的精确控制。其基本原理是利用微控制器内部的定时器和比较器,生成具有特定时序的方波信号,驱动功率开关器件。这项技术的核心价值在于将复杂的模拟控制环路数字化,从而提升系统的可控性、灵活性和可靠性。在电机驱动、不间断电源(UPS)、服务器电源和新能源逆变器等广泛应用场景中,PWM技术都是实现高效能量转换的基石。本文聚焦于德州仪器(TI)C2000系列微控制器中功能强大的增强型PWM(ePWM)模块

weixin_30410119的博客 341

Codeforces Round 869 (Div. 2) (A~C)

感觉这场好靠直觉以及猜测,有时候感觉就不能完全说服自己。

m0_61923501的博客 552

在 RAP 中把业务对象“搬到网口上”:service definition 与 service binding 的全流程、范式与实战

本文解析了SAP ABAP开发中service definition和service binding的关键作用。service definition负责选择要暴露的CDS实体和行为,形成服务模型;而service binding则将服务绑定到具体协议(如OData),生成可访问的端点。两者分离带来三大优势:支持同一模型多重发布、降低环境迁移耦合度、强化安全治理。文章通过预订业务对象的端到端示例,展示了如何从CDS建模到生成Fiori Elements预览。最后以售后工单业务为例,说明这种架构如何支持内外服务

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 390

第六天 界面操作及美化(6.4 使用GUI 套件)

本文介绍如何使用VIPM工具安装DMC GUI套件:首先打开VIPM并连接网络,搜索"UI"找到DMCGUI套件后下载安装;安装完成后即可在VIPM中添加控件并预览效果。该方法同样适用于下载其他UI套件,用户可根据需求设计个性化界面。整个流程包括搜索、下载、安装和使用四个简单步骤,适合快速搭建GUI界面。

weixin_38637405的博客 407

codeforces Longest Increasing Subsequence

Longest Increasing Subsequence

To_c_t_w 537

2023推免(夏令营+套实验室)面试总结(博文附问题汇总和参考答案)

2023推免(夏令营+套实验室)面试总结(博文附问题汇总和参考答案)

m0_51339444的博客 1804

Codeforces Round 869 A-C 题解

null。

qq_30026289的博客 1319

ESP8266-Arduino网络编程实例-异步TCP客户端

本次实例将使用ESPAsyncTCP库实现一个简单的客户端。

视觉与物联智能 1740

语言大模型之Tokenization的深入理解

Tokenization(分词)是自然语言处理(NLP)中一个非常重要的步骤,它的目标是将文本转换为模型可以理解的格式。对于像GPT、BERT等大型预训练模型来说,tokenization决定了文本如何转化为数字表示,从而影响模型在不同任务中的表现。接下来我会深入介绍tokenization的过程、不同的tokenization方法,以及它与模型微调(fine-tuning)之间的关系。

JustinMars的博客 341

Codeforces Round 869 (Div. 2) A~C

偶数:奇偶数相间排布保证连续的两个数不能被2整除,若按顺序奇偶排布,假设从头开始三个为一组,每组去均值之后是1 2 3,这样不合法。每个奇数和它后面的偶数交换位置,每组去均值之后是2 1 4,这样可以。这样排布,若以四个为一组,每组去均值之后都是2 1 4 3,和为10,不能被4整除……暴力一定会超时,所以需要首先预处理出来所有almost-increasing的区间(其实不用PII存也可以,因为almost-increasing的区间长度一定是3,如果有重叠就按两个区间来算)

m0_65620244的博客 715

RK平台内核“大瘦身”:从4GB到500MB的蜕变之旅

摘要:本文详细介绍了RK平台内核裁剪的完整流程与技术要点。通过对RK3568/RK3588等SoC平台的分析,探讨了从初始4GB内核精简至500MB的具体方法。文章系统阐述了前期硬件环境搭建、软件工具准备、SDK源码获取等准备工作,深入解析了内核模块组成及可裁剪部分,并提供了图形化配置界面的详细操作指南。同时,对编译烧录过程和常见问题解决方案进行了说明,强调了备份和谨慎选择裁剪项的重要性。最后展望了内核裁剪技术在物联网和边缘计算等领域的应用前景,为开发者提供了实用的内核优化参考方案。(148字)

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 442

Codeforces 869C Round #439 Div2 C:排列组合计数

题意:给出三片点,第一片点是红色,第二片是蓝色,第三片是紫色。现在要求你往上边加一些边,得到一个合法方案是:同颜色的两个点,要么不可达,要么最短路长度>=3。求出所有合法方案数。 题解:显然三种颜色,最短路>=3,肯定这里面有猫腻,首先显然,两个相同颜色的点不能连边,那么我们考虑一下这个最短路>=3是怎么来的。每个点只能直接连接到不同颜色的点,而这个不同颜色的点不能再连第二条边到颜色1的

辣鸡葫芦娃 781

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

深挖C++:类和对象(中)

(先进后出)

xys_678的博客 222

OV9734 DATASHEET,完整规格书

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

选型笔记:Type‑C 扩展坞方案评估|DP1.4 转 HDMI2.0 桥接芯片 GSV2201S@ACP

本文记录 GSV2201S 这款 DP1.4a 转 HDMI2.0 桥接芯片评估,梳理视频、HDCP、PD 集成能力,总结 Type‑C 转接 Dongle、扩展坞方案的适配边界,以及差分走线、PD 时序、HDCP 握手等高频调试问题,为 C 口视频转接方案选型提供参考。

ACP广源盛的博客 219

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

C++移动构造函数详解

移动构造函数是C++11引入的一种特殊构造函数,用于从临时对象(右值)"窃取"资源来初始化新对象,而不是进行昂贵的深拷贝。char* data;public:// 移动构造函数:参数是右值引用 &&// 关键:把源对象的资源置空。

拒绝AI文,努力在AI时代写出感动人心的好文章 388

ThunderKittens 深度解析:一个不基于 MLIR 的 C++ 模板 GPU DSL

Triton 是"让更多人能写 GPU kernel",ThunderKittens 是"让会写的人写得更爽"。前者用 MLIR 换易用性,后者用 C++ 模板换可控性。它们不是替代关系,而是覆盖了 GPU 编程光谱的两端。ThunderKittens 的出现,本质上是对"GPU DSL 必须基于 MLIR"这一默认假设的挑战。编译期类型系统本身就可以是一个强大的 DSL 基础设施,不需要中间 IR,不需要黑盒 pass,也能实现 tile 级抽象和零运行时开销。

Maxwell_Newton的博客 333

【C语言】字符与字符串函数

C语言中字符串为以\0结尾的字符数组,标准库函数基于此约定。本文解析字符串内存布局,详解ctype.h与string.h中字符分类、长度计算、拷贝、比较等函数的使用要点,强调长度判断与越界风险,最后通过命令行待办事项示例整合fgets、sscanf、strncpy、strcmp,展示实际应用中的关键细节。

记录在学习过程中学到的知识 343

C++ 多态详解:作用、原理与实战用法

多态是C++面向对象的核心特性,通过虚函数实现运行期动态绑定,使同一接口在不同对象上表现出不同行为。其核心作用包括统一接口、提升可扩展性、降低耦合、支持运行时分派与批量处理。实现依赖虚函数表(vtable)和虚指针(vptr),需注意虚析构函数、对象切片等陷阱。相比编译期多态(模板),运行期多态灵活性高但有调用开销。合理结合两者,可兼顾代码的灵活性与性能,是构建可扩展、低耦合系统的关键。

2402_85743155的博客 377

C++ 函数模版

模板参数:● template ,T 就是类型占位符,名字可以自定义,习惯用T● 占位符可以在函数返回值、形参、函数内部当作类型使用使用要点模板代码一般写在头文件:编译器需要看到完整模板源码,才能在每个编译单元完成实例化全局函数、类内成员函数都可以写成模板实例化发生在编译阶段,不是运行时隐式实例化:调用时编译器自动推导实参类型,生成对应版本函数。

2501_94041724的博客 303

C++ 运行时多态与虚函数机制全面剖析【面试重点】

构成C++ 运行时多态必须是基类的指针或者引用调用虚函数。被调用的函数必须是虚函数,并且派生类必须对该虚函数完成重写/覆盖(Override)。只有基类的指针或引用才能既指向基类对象,又指向派生类对象(切片机制);而只有完成了虚函数重写,派生类与基类才具备不同的函数行为,达到“指向谁就调用谁”的效果。在类成员函数的前面加上virtual关键字修饰,该成员函数就成为了虚函数。public:// 成员函数前加 virtual 修饰,声明为虚函数。

Fuyo_0209的博客 435

#SQLite 数据库笔记一:(概念 / 终端指令 / SQL 语句 / C 编程 / 回调函数)

数据库 = 数据的仓库,假设数据是海量。能力说明存储数据持久化保存,程序退出数据还在统计数据、分组、排序数据管理增、删、改、查(CRUD)嵌入式设备上也会用数据库(单片机网关、路由器、工业 HMI 都常见),因为 sqlite 体积小、无需服务进程、单文件即可。数据库 = 库 > 表 > 记录(行) > 字段(列)sqlite3 = 开源、C 写的、单文件、免安装、最多 2T 的嵌入式关系型数据库。

lwq20051110的博客 148

【C++】【STL】string_OJ题

本文总结了9道C++ STL中关于string的OJ题目,按操作类型分为三组:反转与就地修改(如917、541、151)、计数与查找(如387、125、58)、模拟与大数运算(如415、43、8)。核心技巧包括双指针收敛、字符分类处理、进位控制及边界值处理。所有题目使用同一套源码,在标准库std::string与自定义容器MyString间切换仅需宏定义,验证结果一致性。代码通过随机测试用例与Trace函数逐行比对,确保逻辑正确性,强调接口对齐的重要性。

这里是Cocatrice的博客,感谢大家一直以来的支持和鼓励,如果对C/C++方向感兴趣的话,可以通过主页的微信名片加Cocatrice的好友,也可以通过邮箱:Chen31980094@163.com 联系,一同加油! 4370

C 语言 malloc() 详解与实战 Demo

本文详解C语言malloc()函数,涵盖其语法、内存原理及实战应用。通过动态整数、数组、结构体与链表的Demo,演示如何安全申请、使用与释放内存,强调避免内存泄漏与空指针检查的重要性,帮助开发者掌握动态内存管理核心技能。

tangPHP的博客 366

【C++ 基础入门】类和对象(上):封装、对象模型与 this 指针

C++类与对象知识(面向过程和面向对象的初步认识,类的初步认识,类的访问限定符及封装,类的作用域、实例化,类的对象模型,this指针)

2601_96587588的博客 873
上一篇: 洛谷 P3390 [模板] 矩阵快速幂 题解
下一篇: 洛谷 P1781 宇宙总统 题解
bbc_ouo
博客等级 码龄3年 2096粉丝 132原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值