Pearls in a Row( CodeForces - 620C,贪心)

Codesys 3.5报警功能配置保姆级教程:从变量定义到确认方式(含REF/ACK详解) 本文详细介绍了Codesys 3.5报警功能的配置流程,从变量定义到确认方式的选择,特别解析了REF和ACK两种确认方式的底层逻辑。通过实战案例和代码示例,帮助工程师快速掌握报警系统的搭建与调试技巧,提升工业自动化项目的可靠性。 阅读详情

一.题目链接:

CodeForces-620C

二.题目大意:

给出一个数字序列,若有数字重复出现则称这一段序列为 “好”,求这个序列中最多有多少个 “好” 序列.

三.分析:

把序列中的元素放入 set 里,并进行查找,若找到,则 ans++,set 清空,记录首尾位置.

详见代码.

四.代码实现:

#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define eps 1e-6
#define PI acos(-1.0)
#define ll long long int
using namespace std;

int a[(int)1e5 * 3 + 10];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    set <int> st;
    vector <int> s;
    vector <int> e;
    int tag = 1;
    for(int i = 1; i <= n; ++i)
    {
        if(st.find(a[i]) != st.end())
        {
            e.push_back(i);
            s.push_back(tag);
            tag = i + 1;
            st.clear();
        }
        else
            st.insert(a[i]);
    }
    int len = s.size();
    if(len)
    {
        printf("%d\n", len);
        for(int i = 0; i < len; ++i)
        {
            if(i == len - 1)///最后一段可能不符合,所以要并进来.
                printf("%d %d\n", s[i], n);
            else
                printf("%d %d\n", s[i], e[i]);
        }
    }
    else
        printf("-1\n");
    return 0;
}

 

苹果生态最佳搭档:Mac mini + OpenClaw + iPhone 远程控制 本文详细介绍如何通过iPhone远程控制Mac mini上的OpenClaw应用,打造高效苹果生态工作流。内容包括:1) 苹果生态整合优势,包括AirDrop、Handoff等功能对比;2) Mac mini配置步骤,涵盖SSH/VNC设置、网络优化及Docker部署OpenClaw;3) iPhone端SSH/VNC客户端选择与Tailscale内网穿透配置;4) 详细SSH密钥设置与连接测试方法。通过这套方案,用户可实现跨设备无缝控制OpenClaw应用,提升远程工作效率。(149字) 阅读详情

相关推荐

绕过ROS2!在RDK X5上直接用Python调用海康相机C++ SDK的避坑指南

本文详细介绍了在RDK X5上绕过ROS2,直接使用Python调用海康相机C++ SDK的轻量化方案。通过Cython构建Python绑定,提取海康相机SDK核心组件,实现高效图像采集。文章涵盖环境准备、Cython接口设计、编译系统配置及性能优化技巧,特别适合ARM64平台开发者。

weixin_33712987的博客 250

C. Pearls in a Row

C. Pearls in a Row 题目大意:有n颗珍珠排成一排,每颗珍珠有一个类型ai,如果每一段中至少存在一个类型出现次数不少于2次,则这一段被称为good segment;求这排珍珠最多有多少个good segment。 思路:贪心。从头到尾遍历找good segment,只要找到符合条件的(最低条件,即某个数出现两次)记录,难点是最后一段的处理,如果恰好有剩余,加到前一段之中。寻

梦载代码 811

Kinect V1结构光激光散斑原理及样式

   对 intel realsense F200 和 Kinect V1的coding pattern原理进行调研,知二者都使用light coding的方式,该方法与传统的coded structure light不同:传统编码结构光(空间编码,时间编码)最终使用的是三角测量的原理计算深度信息;light coding通过投射具有高度伪随机性的激光散斑,会随着不同距离变换不同

松间明月 1万+

CodeForces - 620C Pearls in a Row 贪心 STL

C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n pearls in a row. Let's enu

祈的博客 300

实战ByteTrack:用C++手把手教你实现多目标跟踪(附完整代码解析)

本文通过C++实战教程,手把手教你实现ByteTrack多目标跟踪算法。文章详细解析了算法核心,包括利用卡尔曼滤波进行状态预测、匈牙利算法完成数据关联,以及ByteTrack独特的三次匹配策略来有效处理低置信度检测框,并提供了完整的项目架构、代码实现与性能优化指南。

yolo5detector的博客 299

Failed to connect to gitee.com port 443: Time out 连接超时提示【Bug已完美解决-鸿蒙开发】

在进行Sample导入或Git项目Clone时,遇到连接超时问题是一个常见而令人烦扰的情况。连接超时问题通常源于网络限制,可能是由于防火墙、代理设置或其他网络配置导致。因此,首先要关注网络状态,确保网络通畅。如果在网络受限的情况下,代理服务器配置是一个有效的解决方案。通过在Git全局配置中设置代理信息,可以将网络请求通过代理服务器传输,规避一些网络限制。但在使用代理时,需要确保代理服务器的可用性和稳定性,以免引入新的问题。

一键难忘的博客 4558

CodeForces - 620C Pearls in a Row 贪心+set

贪心做法  从前往后扫,遇到出现过的就记录下来,重新往后扫 思想:后面留下的串越长,越有可能划分成更多的串 ps : 开始看错题意了,以为是 以同样的数划分,那样的话就是出现次数最多的数划分 #include #include #include #include #include #include #include #include #include #include #i

床前明月光 313

DeerFlow 系列教程 第三篇 | 核心技术深度剖析:Skills、Memory 与 Context Engineering

摘要化是 Context Engineering 中最关键的组件——它直接决定了长对话的可用性。Skills 技能系统通过渐进式加载的三层模型,在保持系统提示词轻量的同时,支持无限数量的技能扩展。从发现到执行的 10 个生命周期阶段,配合 AI 驱动的安全扫描和多层缓存,构成了一个生产级的技能管理框架。Memory 长期记忆系统通过文件系统持久化、LLM 驱动的信息提取和防抖动异步更新,实现了跨会话的认知持久化。六类事实分类体系和修正信号检测机制,让 Agent 能够从交互中持续学习和改进。

weixin_43674738的博客 280

Codeforces--620C--Pearls in a Row

题目描述: There are n pearls in a row. Let’s enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let’s call a sequence of consecutive pearls a segment....

猩猩是个好程序员的博客 359

福建公共资源交易平台 portal-sign与响应Data解密逆向实录

本文分析了福建公共资源交易电子公共服务平台的接口加密机制。通过抓包和代码分析,发现请求头中的portal-sign由MD5算法生成,包含固定秘钥和排序后的参数拼接。响应数据采用AES-256-CBC加密,需使用特定Key和IV解密。文章详细介绍了签名生成规则、参数处理流程及加密常量定位方法,为接口对接提供了技术参考。整个过程展示了如何通过逆向工程还原前端加密逻辑,最终实现脱离浏览器环境的纯协议调用。

自成背后的博客 1158

使用IGV软件可视化染色质可及性

染色质可及性(chromatin accessibility)是指DNA序列在植物细胞核中的可访问程度。染色质是由DNA和蛋白质组成的复杂结构,它紧密地包裹在细胞核中,并影响基因的表达和功能。染色质可及性研究着重于理解染色质是否容易被转录因子和其他调控蛋白访问,从而影响基因的表达。文献中,常常会有下面这种图片来表示基因组上的一些区域或基因的染色质开放性强弱。一般情况下,我们可以使用IGV软件或GSA-man软件进行可视化,两者的操作相似。这里,以IGV软件为例,演示如何对染色质可及性进行可视化。

沉香best的博客 3724

Codeforces-Edu6-C.Pearls in a Row

C. Pearls in a Row time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are n pearls in a row. Let’s enumerate them with integers from 1

PrConstantin 867

在ABAQUS中使用VUMAT子程序实现Hashin失效准则的详细解析与实践:深入探讨复合材料模拟仿真的高级编程技巧

Hashin失效准则是由材料科学家Shlomo Hashin于1962年提出的一种基于能量方法的多向失效理论,主要用于预测复合材料的破坏行为。与传统的单向失效理论不同,Hashin准则考虑了材料内部的多种独立破坏机制,如基体断裂、界面脱粘、纤维断裂等,这些机制在不同应力状态下可能同时或分别发生。通过计算各个机制的能量释放率,Hashin失效准则能够更为准确地预测复合材料在复杂应力状态下的破坏行为。

qq_38334677的博客 1949

Codeforces 620C Pearls in a Row(贪心)

题目链接:http://codeforces.com/problemset/problem/620/C 题意:给出一个n大小的序列,截取一段,如果这一段有2个相同的数字,那么就是好的子序列,问最多有几个好子序列 思路:从头开始遍历,碰到第一个出现2次的数字就把这段数字截取,我感觉第3个样例输出1 3,5 7应该也符合题意,但是wa了……注意的是LL要用map进行

csdn364988181的博客 855

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

深度学习工具包 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")

CodeForces 620 C. Pearls in a Row(贪心)

Description 给出一个长度为n的序列,定义一个子段是好的如果这个子段中含有两个同样的数,问这个序列最多可以被划分成几个好的子段,如果不能被划分则输出-1 Input 第一行为一整数n表示序列长度,之后n个整数ai表示该序列(1<=n<=3*10^5,1<=ai<=10^9) Output 如果这个序列可以被划分成多个好的子段则输出最多的子段数和每个子段的起始终止位置,否则输出-1

ZSQ 881

精雕软件(JDpaint) 5.5 绿色版

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

CodeForces - 620C Pearls in a Row |set,贪心

DescriptionThere are n pearls in a row. Let’s enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.Let’s call a sequence of consecutive pearls a segme

xinxiaxindong的博客 345

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Pearls in a Row CodeForces - 620C

There are n pearls in a row. Let’s enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.Let’s call a sequence of consecutive pearls a segment. Let’s c

Hanylch 416

Educational Codeforces Round 6 C. Pearls in a Row(贪心)

大致思路:用map记录当前一段某类型的珍珠是否出现过,如果当前珍珠的类型已出现过,则将其与前面的珍珠分成一段。【注意】需特殊处理最后一段珍珠,让其结尾到项链尾部

idealism_xxm的专栏 662

Educational Codeforces Round 6 620C Pearls in a Row

codeforces 620C

wchhlbt的博客 538

城域网IPv6演进实战:NAT444与DS-lite选型与部署场景剖析

本文深入剖析城域网IPv6演进中的NAT444与DS-lite技术选型与部署场景。通过对比分析两种过渡技术的原理、成本与兼容性,为运营商提供实战决策框架。NAT444适合老旧设备改造,而DS-lite在IPv6单栈管理方面具有前瞻优势,文章结合具体案例给出混合部署建议。

weixin_30399155的博客 533

CodeForces - 620C

这本也是个水题。但我还是WA了好久。看到题后直接想法是DP,贪心策略是由一对重复的就停下分割成一段区间。所以如果当前这个数字出现过在m[a[i]],那么f[i]=f[m[a[i]]-1]+1,f[i],不然f[i]就只能f[i-1],然而这道题要求输出方案,这就难死我了。我用个frm[i]记录每一个区间从哪转移过来,然后又要判断从f[i-1]转移过来的怎么分配,十分麻烦。然而今天学长讲了题解,卧槽...

binarycopycode 251

CodeForces - 620C (贪心)详解

There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let'...

PCCCCC的博客 577

codeforces 620C

题目链接:https://codeforces.com/problemset/problem/620/C 题目分析 题意:给你一串珍珠,每个珍珠都有一个对应值,需要分割这n个珍珠(必须连续),使得每一串珍珠中含有对应值相同的两个珍珠,并让这个样的珍珠串数目达到最多。 首先看到这个题目的时候想用数组保存各个数出现的位置的,但是由于题目...

weixin_34259159的博客 199

Educational Codeforces Round 6 C. Pearls in a Row

题意: 找到最大连续有重复数字的子段 #include #include #include #include #include using namespace std; const int maxn=300005; int a[maxn]; int l[maxn]; int r[maxn]; int now[maxn]; int main() { mapmp;

GameRoad 294

CodeForces 620C Pearls in a Row

C. Pearls in a Rowtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n pearls in a row. Let's enumerate them with integers from 1 to n from...

Lngxling的博客 325
上一篇: Replace To Make Regular Bracket Sequence (CodeForces - 612C ,栈实现括号配对)
下一篇: 迷宫问题 (POJ - 3984 ,BFS + 路径输出)
The___Flash
博客等级 码龄8年 79粉丝 223原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值