Codeforces Round #336 (Div. 2)

A. Saitama Destroys Hotel

【题意】一楼梯从最高层开始依次下降,每下一层花1s,如果该层有人,则等乘客到达后载客继续下降,乘客进电梯的时间忽略不计,给定有乘客的楼层数及乘客到达时间,求承载所有乘客下至第0层所花费的最小时间。
【代码】

#include<iostream>
using namespace std;
int main (void)
{
    int n,s;
    int minutes=0;
    int f[1005],t[1005];
    cin>>n>>s;
    for(int i=0;i<n;i++){
        cin>>f[i]>>t[i];
    }
    f[n]=s;
   for(int i=n-1;i>=0;i--){
        minutes+=f[i+1]-f[i];
        if(minutes<t[i])  minutes=t[i];
   }
    cout<<minutes+f[0]<<endl;
    return 0;
}

B. Hamming Distance Sum

【题意】给定两个字符串a,b,求b中所有跟a长度相同的子串中,各个字符与a中相应字符的差的绝对值的和。
【分析】对于字符串b中每个字符,记录该字符之前包含该字符在内的子串中0,1出现的次数。对于长度为lena的字符串a,长度为lenb的字符串b,a中第i个字符可以与b中第i到第lenb-lena+i个字符进行比较。若a中字符为0,则最后结果加上该区间内的字符为1的字符个数,若为1,则加上字符为0的个数。
【代码】

#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=200005;
char a[maxn],b[maxn];
int main (void)
{
    cin>>a>>b;
    int lena=strlen(a);
    int lenb=strlen(b);
    long long r=0;
    int d1[maxn],d0[maxn];

    r=0;
    for(int i=0;i<lenb;i++){
        d0[i]=d0[i-1];
        d1[i]=d1[i-1];
        if(b[i]=='0') d0[i]++;
        else d1[i]++;
    }
    for(int i=0;i<lena;i++){
        if(a[i]=='0')r+=d1[lenb-lena+i]-d1[i-1];
        else r+=d0[lenb-lena+i]-d0[i-1];
    }
    cout<<r<<endl;
    return 0;
}

C. Chain Reaction

【题意】一连串灯塔,从左到右排列,位于位置a[i]的灯塔,激活后,可以破坏距离为b[i]范围内的其他灯塔,灯塔仅可向左边攻击,攻击他人自己不受损坏,受损的灯塔不能被再次激活。 现在整个排列的最右边放置一个灯塔,使得从右向左依次激活灯塔后,受破坏的灯塔个数最少。
【分析】激活最右边的灯塔之后,所有被破坏的灯塔中距离激活的灯塔最远的灯塔左边的灯塔得以存活,所以从左向右依次记录激活该灯塔后,左边剩余灯塔个数,算出最大值,用总灯塔数减去该最大值。
【代码】

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int m[1000005];
int dp[1000005];
int main (void)
{
    int n;
    cin>>n;
    int x,y;
    int mins=0x3ffffff;
    int maxn=0;
    for(int i = 0; i < n; i++){
        cin>>x>>y;
        m[x]=y;
        mins=min(mins,x);
        maxn=max(maxn,x);
    }
    for(int i = mins; i <= maxn; i++){
            if(!m[i]) {dp[i]=dp[i-1]; continue;}
            if(i-m[i]-1>=0) dp[i]=dp[i-m[i]-1]+1;
            else dp[i]=1;
    }
    long long  ans=0;
    for(int i = mins; i <= maxn; i++){
       if(ans<dp[i]) ans=dp[i];
    }
    cout<<n-ans<<endl;
    return 0;
}

转载于:https://www.cnblogs.com/Tuesdayzz/p/5758859.html

计算图像哈希SHA-512 上述需要将lena.jpg放在当前目录下。 阅读详情

相关推荐

GPS定位不准?可能是GDOP在作怪!手把手教你优化卫星几何分布

本文深入解析了GPS定位精度不佳的常见原因——几何精度因子GDOP。通过剖析卫星几何分布对定位误差的放大效应,文章提供了从理解GDOP、PDOP、HDOP等关键指标,到使用专业APP实时诊断卫星天空图,再到利用在线工具提前规划最佳定位时机的完整实战指南。旨在帮助户外爱好者、无人机飞手及专业用户主动优化卫星几何条件,从而显著提升定位可靠性。

weixin_29062823的博客 309

Codeforces Round #336 (Div. 2) 总结

A. Saitama Destroys Hotel time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Saitama accidentally destroyed a h

小马的博客 676

基于OpenAI Agents构建多智能体工作流:从原理到实战

多智能体系统(Multi-Agent System)是人工智能领域的重要分支,它通过多个智能体(Agent)的协作与交互,解决单一智能体难以处理的复杂任务。其核心原理在于将任务分解、分配与协调,每个智能体具备特定能力,通过通信机制实现信息共享与决策协同。在工程实践中,多智能体框架的价值在于提升任务处理效率、增强系统鲁棒性,并支持模块化开发。典型的应用场景包括自动化工作流编排、复杂问题求解以及人机协同交互。本文以OpenAI Agents SDK为例,深入探讨如何利用其提供的智能体(Agent)、会话(Ses

weixin_28725959的博客 612

Codeforces Round #336 (Div. 2) D. Zuma

D - Zuma 题意:给你一个数字组成的串, 每次你能消去一段连续的回文串,问你最少需要操作几次把所有数字删完。 思路:区间dp, dp[ i ][ j ]表示删 i 到 j 段最少需要几次。 我们只考虑最左边的那个点的删除情况。 首先dp[ i ] [ j ] <= dp[ i + 1] [ j ] + 1 然后我们枚举 i 到 j 里面的点, 找到a[ k ] ...

185

信号与系统——卷积、相关运算与FFT关系以及工程应用(三)

卷积运算、相关运算

qq_35028634的博客 6621

Altium Designer 16来自原理图/PCB的各种报错 (持续更新):

NO1.Nets with only one pin: 根本原因: 在BGA的原理图绘制时,我一般习惯拉出该元件的所有IO的网络,这方便利于我开发其他款板卡。同样也会因为不同板卡的需求不同而造成有些IO并没有使用到,也就是整个原理图中only one pin。 解决方案: 鼠标右键工程文件>工程参数>下图圈中的选项将“错误”更改为“警告/不报告” ...

CSDN@猿谷攻城狮 1万+

Codeforces Round #336 div2

Codeforces Round #336 div2 通过数:3(1题未来得及交) Standing: 418 题目链接: http://codeforces.com/contest/608 A: 到一个楼层的时候,如果有人,则更新ans = Max(ans, 此人等待时间)#include <cstdio> #include <cstring> #include <cma

beihai2013 387

基于cnn version_transformer VIT模型的动物图像分类 完整代码+数据 动物分类教程

基于cnn version_transformer VIT模型的动物图像分类 完整代码+数据 动物分类教程

机器学习深度学习业余选手 1006

Codeforces Round #336 (Div. 2) D. Zuma

Codeforces Round #336 (Div. 2) D. Zuma 题意:输入一个字符串;每次消去一个回文串,问最少消去的次数为多少? 思路:一般对于可以从中间操作的,一般看成是从头开始(因为只需要考虑一边),当考虑最左边的数时,有多少中消去方法?每种消去方法对结果的贡献又是多少?同时结果的区间又是怎么变化?这就是dp式子; 1.当单独消去这个元素时,dp[l][r] = 1 + dp[l

hxer 390

Yolo8行人车辆目标检测实战分享 完整项目代码可直接运行

Yolo8行人车辆目标检测实战分享 完整项目代码可直接运行

1300

【YOLO系列】YOLOv11详解:模型结构、损失函数、训练方法及代码实现

YOLOv11在目标检测领域实现重大突破,通过动态骨干网络(Dyna-Backbone)和FPN++架构,在保持高帧率(≥60FPS)的同时提升小目标检测精度(AP_S提升5.6%)。创新采用CIoU++损失函数和类别平衡Focal Loss,结合Mosaic-Plus数据增强,参数量减少18%至6.5M。实验显示,该模型在COCO数据集上实现更高mAP,特别适合移动端部署,Jetson Xavier平台能耗比优化至3.2W·ms⁻¹,支持目标检测、实例分割等多任务场景。关键创新包括动态深度调整和双向特征金

一碗白开水一 3445

Codeforces Round #336 (Div. 2)D. Zuma【区间dp】

D. Zuma time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Genos recently installed the game Zuma on his phone

走一步再走一步 565

PCL点云库入门(第6讲)——PCL库中Eigen数学工具库的基本使用(持续更新)

Eigen库是一个高性能的C++模板库,专注于线性代数、矩阵和向量运算,以及相关的数值分析和算法。在Eigen库中,所有的矩阵和向量均被视为矩阵模板类的实例。向量可以被看作是特殊形式的矩阵,具体表现为只包含1行或1列。

qq_36812406的博客 1756

Codeforces Round #336 (Div. 2) B 暴力

链接:戳这里 B. Hamming Distance Sum time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Genos needs your help. He was asked to solve the

Cross 375

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Codeforces Round #336 (Div. 2)C. Chain Reaction

C. Chain Reaction time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n beacons located at distinct p

走一步再走一步 716

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Codeforces Round #336 (Div.2)

                  A. Saitama Destroys Hotel time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Saitama accidentally des...

weixin_34224941的博客 213

[Codeforces Round #195 DIV2B (CF336B)] Vasily the Bear and Fly

题意题面比较复杂 2m2m个圆排成两排,每排mm个圆。标号以排连续 天数从00到m2−1m^2-1,第ii天时,苍蝇从v=⌊im⌋+1v=\lfloor \frac i m \rfloor + 1出发,到u=m+1+(imodm)u=m+1+(i\mod m)去,在路径在圆内部前提下沿着最短路飞行。求飞行距离的平均长度。 样例 2 2 题解分析一下起点和终点会发现起点在第一排,终点在第二排

ztx 424

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 to solve the fo

KeyboardPianist的博客 813

Codeforces Round #336 (Div. 2) C. Chain Reaction

C. Chain Reaction time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n beacons located at distinct positions on a number

KeyboardPianist的博客 605
上一篇: HDU 1754_I Hate It
下一篇: ZOJ 1298_Domino Effect
An55511
博客等级 码龄10年 1粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值