【解题报告】Educational Codeforces Round 12

【解题报告】 Educational Codeforces Round 19 简略的解题报告。 阅读详情

题目链接


A.Buses Between Cities(Codeforces 665A)

思路

假设主角的车在 s 时刻出发,在t时刻到达。那么在这个时间段内在道路上出现过的由B驶来的车辆的数量 ans 就是答案。我们不管中间复杂的过程(其实也不怎么复杂)而只考虑 s 和 t 这两个时刻,那么 ans=s 时刻还在公路上的从B驶来的车的数量 num1+ 在 s 时刻与 t 时刻之间的时间段内新出发的从 B 出发的车的数量 num2 。显然, num1=s 时刻之前B的发车数量 −s 时刻从 B 发出的已经到达 A 的车的数量, num2=t 时刻之前的发车数量 −s 时刻之前的发车数量。化简上面三个式子后得到最终的等式: ans=t 时刻之前的发车数量 x−s 时刻从 B 出发的已经到达 A 的车的数量 y ,即 ans=x−y 。根据已给的数据计算 x 和 y 即可。在计算 x 的时候要注意 t 时刻是否在末班车发车时间之后,在计算 y 的时候要注意主角的车子出发时是否已经有由 B 出发的车子到达 A 。
(另外,因为数据规模较小,用模拟的方法貌似也可以做)

代码

#include <cstdio>

const int first = 5 * 60, final = 23 * 60 + 59;
int fa, ta, fb, tb, h, m, s, t, x, y;

int main() {
    scanf("%d%d%d%d%d:%d", &fa, &ta, &fb, &tb, &h, &m);
    s = 60 * h + m - first;
    t = s + ta;
    if(t <= final - first) {
        x = t / fb + (t % fb != 0);
    }
    else {
        x = (final - first) / fb + 1;
    }
    y = s < tb ? 0 : (s - tb) / fb + 1;
    printf("%d\n", x - y);
    return 0;
}

B. Shopping(Codeforces 665B)

思路

因为数据规模比较小,所以可以直接模拟(数组或双端队列)。

代码

#include <bits/stdc++.h>
using namespace std;

int n, m, k, item, ans;
deque <int> :: iterator it;
deque <int> d;

int main() {
    cin >> n >> m >> k;
    while(k--) {
        cin >> item;
        d.push_back(item);
    }
    ans = 0;
    for(int i = 0; i < n * m; i++) {
        cin >> item;
        for(it = d.begin(); it != d.end(); it++) {
            ans++;
            if(*it != item) {
                continue;
            }
            d.erase(it);
            break;
        }
        d.push_front(item);
    }
    cout << ans << endl;
    return 0;
}

C. Simple Strings(Codeforces 655C)

思路

首先从题目给的数据量来看,题目给的时间似乎只够设计 O(n) 的算法。目标是用最小的修改次数构造出没有相邻的相同字符的字符串。那么显然,当字符串中出现两个相邻的字符的时候,两个必然有一个要被修改掉。修改哪一个呢?下面举例说明。字符串 aabbc ,对于子串 aa 修改后面那个 a 显然更好些,因为我可以将后面那个 a 修改成与 b 不同的字符 c ,这样就一次性解决了这个重复而不会引起其它的重复。到此,我们显然能够设计出这样的贪心算法:从头到尾扫描字符串,假设扫描到第 i 位,如果出现 s[i]==s[i+1] 的话 s[i+1]++ ,自加以后如果 s[i+1]==s[i+2] 则 s[i+1]++ 。

代码
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
char s[maxn];
int n;

int main() {
    scanf("%s", s);
    n = strlen(s);
    for(int i = 1; i < n; i++) {
        if(s[i] == s[i-1]) {
            s[i] = (s[i] - 'a' + 1) % 26 + 'a';
            if(i + 1 < n && s[i] == s[i+1]) {
                s[i] = (s[i] - 'a' + 1) % 26 + 'a';
            }
        }
    }
    printf("%s\n", s);
    return 0;
}

(其它题目略)

【解题报告】Educational Codeforces Round 20 简略的解题报告。 阅读详情

相关推荐

【解题报告】Educational Codeforces Round 15

简略的解题报告。

TRiddle的博客 1045

Codeforces Educational Round 12 655ABCDE

Codeforces Educational Round 12 通过数: 3 A: 刚开始用公式分类讨论,后面发现暴力才是一种更优美的解法#include <bits/stdc++.h> using namespace std; const int MAXN = 10 + 5; char str[MAXN]; int main() { int x1, y1, x2, y2; w

beihai2013 488

Windows版MySQL8.4.2LTS解压直用(下载免安装-绿色-项目打包直接使用-含卸载)

安装前运行微软常用运行库全集(也可能称为依赖)关于MySQL8中相关参数配置,可通过。选择8.5.2LTS长期服务版。选中密码,右键会直接复制。

xzzteach的博客 1440

Educational Codeforces Round 12

Educational Codeforces Round 12 原题地址 A. Buses Between Cities 题意 给出 A 市到 B 市和 B 市到 A 市公交车、出发的频率以及需要的时间。判断当坐从 A 市到 B 市的某一辆车时,在到达 B 市的图中遇到的公交车的数量。 分析 遇到的公交车共有两种 在 m 时刻从前出发但未到站 在 m 时刻之后出发 枚举所有从 B 市出发的车,然后判断是否可以遇到 代码 public static void solve() throws IOExcep

w_weirdo的博客 259

数字后端设计实现 | 数字后端PR工具Innovus中如何创建不同高度的row?

数字IC后端设计实现之innovus中如何创建不同高度的row?

weixin_37584728的博客 3163

通达信双紫擒龙指标实战指南:从源码解析到精准安装

本文详细解析了通达信双紫擒龙指标的核心逻辑、源码获取与安全验证、安装流程及实战应用技巧。通过紫紫红黄四种颜色信号捕捉趋势转折点,结合MACD、布林通道和成交量加权算法,提升交易准确性。文章还提供了个性化设置、信号解读及常见问题解决方案,帮助投资者高效运用该指标。

weixin_29248611的博客 1050

Windows下PyImageJ环境配置避坑全记录:从JVM报错到成功运行第一个宏

本文详细记录了在Windows系统下配置PyImageJ环境的完整过程,从解决JVM报错到成功运行第一个宏。特别针对Java与Python环境配置中的常见陷阱、路径权限问题以及初始化失败的原因提供了实用解决方案,帮助研究人员高效整合ImageJ与Python生态。

weixin_30608503的博客 652

车载与安防项目实战:如何用RK3588搭配NVP6158C实现4路AHD摄像头BT1120接入与同步预览

本文详细解析了基于RK3588处理器与NVP6158C解码芯片实现4路AHD摄像头BT1120接入与同步预览的技术方案。针对车载环视和安防监控场景,重点探讨了硬件架构设计、BT1120接口配置、多路同步机制及Android HAL适配等核心问题,提供了从底层驱动到上层应用的完整实现路径,为相关领域的工程实践提供可靠参考。

weixin_30571465的博客 486

Educational Codeforces Round 12 C.Simple Strings

zscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is g

逆水行舟,不进则退 461

Python实现高光谱图像生成与增强:从RGB到多光谱转换(附完整代码)

本文分享一个基于Python的实用工具,能够将普通RGB图像转换为模拟高光谱图像,并进一步生成增强的彩色可见图像。为了直观展示图像细节,程序通过对特定波段的组合,生成了一幅增强的 RGB 彩色图像。该函数的主要目标是将一张普通的 RGB 图像转换为包含多个波段的高光谱图像。通过该函数,我们能直观地看到高光谱图像经过波段组合后所得到的彩色图像效果。通过以上代码,我们可以实现对海量图像数据的自动化处理,极大地提升工作效率。已附在文中,欢迎下载测试!通过以上步骤,我们可以生成一幅包含多个光谱波段信息的图像。

m0_74824642的博客 3665

【项目实战】SOVD协议(面向服务的车辆诊断协议)

此外,AUTOSAR组织将SOVD部分内容的软件实现定义在了R22-11及以上版本的AUTOSAR Adaptive规范中,还支持动态发现车内诊断功能、获取高性能计算机(HPC)的Log信息等新的诊断需求,更符合当前软件定义汽车概念下的行业趋势。而SOVDGateway作为边缘节点,也肩负着对SOVD Client进行认证以及权限控制的责任,从而保证车辆的信息安全。相较于传统的UDS(Unified Diagnostic Services)协议,SOVD不仅保留了传统的读写数据、例程控制、故障读取等功能,

奶爸的编程之路,也就一周冷个三天 1905

【解题报告】Educational Codeforces Round 13

简略的解题报告。

TRiddle的博客 1416

【Java核心高阶进阶】44-Java8核心新特性

模块十:Java新特性演进 · 第 1 篇Java 8 是 Java 语言历史上最重要的一次发布,它引入的函数式编程范式从根本上改变了 Java 的编码方式。即便到了 JDK 21 的今天,Lambda、Stream、Optional 仍是日常开发的高频工具。本篇将深入这些特性的语法、原理与底层机制,帮助你不仅会用,更知其所以然。

gaochufukanyongren的博客 24

Codeforces Educational Round 95 解题报告

Codeforces Educational Round 95 解题报告 A. 题解: ​ 计算出所需要的棍子数量 sticks = k * ( y + 1),然后答案是 (stick−1)/(x−1)+((stick−1)mod  (x−1)==0?1:0)+k (stick - 1)/(x - 1) + ((stick-1)\mod (x-1) == 0 ? 1 : 0) + k (stick−1)/(x−1)+((stick−1)mod(x−1)==0?1:0)+k B. 题解: ​ 将unlocke

一个蒟蒻的博客 364

基于STM32F103设计的智能门锁(支持多种开锁解锁方式)

这个智能锁模型是基于STM32平台开发的,支持多种开锁方式。其中,一种是使用RC522射频卡读卡器读取IC卡卡号和内部数据,并验证身份后开锁;另一种是通过连接蓝牙地址来确认业主身份,实现了蓝牙自动开锁功能;最后一种是通过ESP8266连接腾讯云物联网平台,并且用户可以通过微信小程序“腾讯连连”进行远程开锁和关锁。这样,用户就可以选择最方便的方式来进行开锁操作了。

3万+

精雕软件(JDpaint) 5.5 绿色版

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

【解题报告】 Educational Codeforces Round 40

题目链接 A. Diagonal Walking(Codeforces 954A) 题意 给出一个仅含RRR和UUU的字符串。问如何进行一系列操作(每次操作可以将连续的RURURU或URURUR替换DDD),使得最后得到的字符串长度最小。 思路 本题的入手点是,先贪心地提出一个算法,再看看有没有更优的算法。 显然,我们可以提出这样的贪心算法:从左到右依次考虑字符串sss...

TRiddle的博客 1152

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

Educational Codeforces Round 81 (Rated for Div. 2)解题报告

Educational Codeforces Round 81 (Rated for Div. 2) 【A.Display The Number】 【题目大意】 问你用n根火柴能表示的最大数字是多少 【解题思路】 容易想到1只需要两根火柴,那么尽量用1,有多的将第一位改为7 【AC代码】 #include <bits/stdc++.h> #define N 100 #define ma...

weixin_44211980的博客 581

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

【解题报告】Educational Codeforces Round 14

简略的解题报告。

TRiddle的博客 938

【解题报告】Educational Codeforces Round 105 | ABCD

【解题报告】Educational Codeforces Round 105 | ABCDA:ABC String | QDB:Berland Crossword | 枚举C:1D Sokoban | 前/后缀和 + 滑动窗口D:Dogeforces | LCA + 贪心重构 Educational Codeforces Round 105 A:ABC String | QD … B:Berland Crossword | 枚举 给 n×nn\times nn×n 白方格染黑,要求最上层、最右层、最下

溢流眼泪的博客 439

【解题报告】Educational Codeforces Round 21

简略的解题报告。

TRiddle的博客 593

Educational Codeforces Round 178 Div. 2

Educational Codeforces Round 178 (Rated for Div. 2)(2104A-2104G)题解

LancyMorry的博客 927

Educational Codeforces Round 112 (Rated for Div. 2) ABCDE 解题思路

Educational Codeforces Round 112 (Rated for Div. 2) 只做了ABCDE,但被AE卡了我是没想到的,CE分别一发RE也傻了 A - PizzaForces 题意 做小尺寸的pizza可以切成666片,要花151515​分钟 做中尺寸的pizza可以切成888​片,要花202020​分钟 做大尺寸的pizza可以切成101010​​片,要花252525​​分钟 现在Petya家来了nnn位客人,他想让每个客人都至少能吃到一块pizza 问做出符合需求数量的p

StelaYuri's Blog 752

Educational Codeforces Round 100 A—D题题解

A. Dungeon 题目传送门: A. Dungeon 题目大意: 三个怪物具有a,b,c的血量,每发射一次炮弹,会对一个怪物造成一点伤害。每发射6次之后,第7次就是蓄力炮,对三个怪物同时造成一点伤害。问三个怪物能不能被同一个蓄力炮同时杀死。 思路: 如果a + b + c 的和sum是9的倍数原因是只有9的倍数才可能被蓄力炮同时秒掉。且min(a,b,c)>=sum/9 ,因为在最后一次蓄力炮之前,每个怪物都不能死。 AC Code #include<bits/stdc++.h> us

稚始稚终的博客 1904

【解题报告】Educational Codeforces Round 9

简略的解题报告。

TRiddle的博客 721

Educational Codeforces Round 92 (Rated for Div. 2)解题报告

Educational Codeforces Round 92 (Rated for Div. 2) A. LCM Problem 题目大意 给定区间[l,r][l, r][l,r],让你找到正整数xxx,yyy满足l≤x<y≤rl \leq x < y \leq rl≤x<y≤r,并且l≤lcm(x,y)≤rl \leq lcm(x, y) \leq rl≤lcm(x,y)≤r 解题思路 根据题意有: l≤lcm(x,y)=x×ygcd(x,y)≤rl \leq lcm(x,y)=\fr

weixin_44211980的博客 286
上一篇: 【解题报告】BestCoder Round #77 (div.2)
下一篇: 【解题报告】Codeforces Round #350 (Div. 2)
TRiddle
博客等级 码龄11年 14粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值