Codeforces Round #196 (Div. 2) / 337D Book of Evil (树的直径变形——树的最长标记弦)

5个4000比特大状态置换算法的设计与分析 下面是 5 个概念性、实验性的 4000 位可逆置换设计。它们都保证是双射,但未经过密码分析,不可直接用于生产系统。风格分别覆盖:三维 SPN、Feistel、可逆元胞自动机、ARX、宽轨迹/Keccak 式结构。 这 5 个设计分别代表了 SPN、Feistel、元胞自动机、ARX、宽轨迹 Keccak 五种不同风格,覆盖了主流大状态置换的构造思路。再次强调:它们只是实验性概念,若要用于实际协议,必须经过严格安全性分析。 阅读详情

http://codeforces.com/contest/337/problem/D


/*154ms,10300KB*/

#include<bits/stdc++.h>
using namespace std;
const int mx = 100005;

vector<int> g[mx];
int d1[mx], d2[mx], p[mx];

void dfs(int p, int u, int deep, int D[])
{
	D[u] = deep;
	for (int i = 0; i < g[u].size(); i++)
	{
		int v = g[u][i];
		if (v != p) dfs(u, v, deep + 1, D); ///这样写就可以不用开vis数组了
	}
}

int main()
{
	int n, m, maxdeep, x, y;
	scanf("%d%d%d", &n, &m, &maxdeep);
	for (int i = 1; i <= m; i++) scanf("%d", &p[i]);
	for (int i = 1; i < n; i++)
	{
		scanf("%d%d", &x, &y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(0, 1, 0, d1);
	int t = 1;
	for (int i = 1; i <= m; i++)
		if (d1[p[i]] > d1[t]) t = p[i]; ///记录受影响的点中离1最远的点t
	dfs(0, t, 0, d1); ///d1是树的最长标记弦上距离点t的深度(t为树的最长标记弦的一端)
	for (int i = 1; i <= m; i++)
		if (d1[p[i]] > d1[t]) t = p[i]; ///树的最长标记弦的另一端
	dfs(0, t, 0, d2); ///d2是树的最长标记弦上距离点t'的深度(t'为树的最长标记弦的相对t另一端)
	int ans = 0;
	for (int i = 1; i <= n; i++)
		if (d1[i] <= maxdeep && d2[i] <= maxdeep) ans++;
	printf("%d\n", ans);
	return 0;
}

从零到一:基于K375S主控的机械键盘优联无线化改造实战 本文详细记录了基于罗技K375S主控进行机械键盘优联无线化改造的全过程。从改造动机、核心原理与物料准备,到电路设计、PCB打样、焊接调试,逐步拆解了将优联技术集成到自定义机械键盘中的实战步骤。项目最终实现了低延迟、高稳定性且支持多设备连接的优联无线机械键盘,为DIY爱好者提供了高性价比的改造方案。 阅读详情

相关推荐

【QT】基于QSerialPort的跨平台串口通信实战指南

本文是一份基于Qt QSerialPort模块的跨平台串口通信实战指南。详细介绍了从硬件基础、QSerialPort核心类使用、参数配置、设备自动发现到数据异步读写和错误处理的完整流程,并通过构建一个功能齐全的串口调试助手实例,帮助开发者快速掌握在Windows、Linux和macOS系统下进行高效、稳定的串口应用开发。

a1b2c3d的博客 981

Manacher 算法详解:O(n) 复杂度求最长回文子串

先预处理下:在每个字符的两边都插入一个特殊的符号,比如abba变成#a#b#b#a#,aba变成#a#b#a#(因为Manacher算法只能处理奇数长度的字符串)。同时,为了避免数组越界,在字符串开头添加另一特殊符号,比如$#a#b#a#。 以字符串3212343219为例,处理后变成S[] = "$#3#2#1#2#3#4#3#2#1#9#"。 然后用一个数组Len[i]来记录以字符S[i

AC,∑ndless 4609

ROS TF坐标转换实战:从零搭建机器人坐标系(附常见问题排查)

本文提供了一份ROS TF坐标转换的实战指南,详细讲解了如何从零为机器人搭建完整的坐标系,并深入解析了TF的原理。内容涵盖静态与动态坐标变换的发布、URDF模型使用、以及Rviz和rqt_tf_tree等可视化调试工具。文章还附带了常见问题排查表,帮助开发者快速定位并解决TF树断裂、数据错位等典型问题。

weixin_29268385的博客 203

Codeforces Round #119 (Div. 2) / 189A Cut Ribbon (完全背包)

A. Cut Ribbon http://codeforces.com/problemset/problem/189/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 2675

TSP:车为什么能和云端交互?

TSP:车为什么能和云端交互?

天赐好车的博客 410

国科大学习资料--遥感原理集图像处理(尤红建)--2019年期末考试

国科大学习资料–遥感原理集图像处理(尤红建)–2019年期末考试 国科大学习资料–遥感原理集图像处理(尤红建)–2019年期末考试 国科大学习资料–遥感原理集图像处理(尤红建)–2019年期末考试 ================================================================== ================================================================== ==============

无名何许人的博客 1469

Codeforces Round #105 (Div. 2) / 148A Insomnia cure (枚举 || 数论)

A. Insomnia cure http://codeforces.com/problemset/problem/148/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 2453

深度解析:C# Modbus TCP协议解析与异常处理(工控上位机必备)

协议解析要精准:掌握MBAP头和PDU的结构,尤其是常用功能码的请求/响应格式,避免因字节处理错误导致通信失败;异常处理要全面:覆盖通信层、协议层、数据层的所有异常类型,针对工业场景制定重试、重连、滤波等策略;资源管理要规范:使用释放资源,采用连接池复用连接,避免端口泄露;工业场景要适配:结合工控现场的特点(网络波动、电磁干扰、设备忙),优化通信效率和数据处理逻辑。通过以上解析和策略,可确保C#上位机与工业设备的Modbus TCP通信具备高稳定性、高可靠性、高容错性,满足工控领域的严苛要求。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 997

Codeforces Beta Round #74 (Div. 2) / 90B African Crossword (模拟)

B. African Crossword http://codeforces.com/problemset/problem/90%2FB time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard o

AC,∑ndless 2416

YOLOv8【第十章:多任务扩展深度篇·第1节】YOLOv8-Seg 实例分割:Mask原型生成与系数预测原理解析!

🏆 本文收录于 《YOLOv8实战:从入门到深度优化》 专栏。该专栏系统复现并梳理全网各类 YOLOv8 改进与实战案例(当前已覆盖分类 / 检测 / 分割 / 追踪 / 关键点 / OBB 检测等方向),坚持持续更新 + 深度解析,质量分长期稳定在 97 分以上,可视为当前市面上 覆盖较全、更新较快、实战导向极强 的 YOLO 改进系列内容之一。

**My Coding Family** 1810

编译zlib库给IOS平台用

在弹出的下面对话框中选择Unix Makefiles ,然后点击(Done)完成。使用 lipo与otool查看库类型为arm64,现在可在ios平台使用该库了。zlib自带CMakeLists.txt 所以用CMake-GUI来生成。修改为与系统当前安装的cmake版本 (如:3.22.1)选择zlib源码目录及输出目录,输入下图的CMAKE参数。点击Configure,在弹出的对话框中选择Yes。cmake --install . 进行安装。cmake --build . 进行编译。

993

Codeforces Round #173 (Div. 2) / 282A Bit++(模拟)

A. Bit++ http://codeforces.com/problemset/problem/282/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 2227

GD32F103 -- LIN从机通讯 -- 程序代码 (精简版)

注意!!!注意!!!这是GD32从机通讯!!!GD32!!!GD32!!!

晴朗luo的博客 2498

Codeforces Round #235 (Div. 2) / 410D Roman and Numbers (带有整除性质的数位DP)

http://codeforces.com/problemset/problem/401/D 解释全部在代码的注释中: /*78ms,205464KB*/ #include using namespace std; const int mx = 1 << 18; long long dp[mx][100]; ///dp[mask][j]表示余数为j时的mask对应的x的个数 ///

AC,∑ndless 2198

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

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

Codeforces Round #194 (Div. 1) / 333A Secrets(贪心)

A. Secrets http://codeforces.com/contest/333/problem/A time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ge

AC,∑ndless 2041

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Codeforces Beta Round #98 (Div. 2) / 137A Postcards and photos (模拟)

A. Postcards and photos http://codeforces.com/problemset/problem/137/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard

AC,∑ndless 2022

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces Round #177 (Div. 1) / 288A Polo the Penguin and Strings(贪心)

A. Polo the Penguin and Strings http://codeforces.com/problemset/problem/288/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output

AC,∑ndless 1932

Codeforces Beta Round #75 (Div. 2) / 92B Binary Number(贪心)

B. Binary Number http://codeforces.com/problemset/problem/92/B time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 1931

Codeforces Round #183 (Div. 1) / 303A Lucky Permutation Triple (强大的数学&想法题)

http://codeforces.com/problemset/problem/303/A when n is odd, A[i] = B[i] = i when n is even, there is no solution. why? If , then  or just , where S = 0 + 1 + ... + n - 1 = n(n - 1) / 

AC,∑ndless 1915

Codeforces Round #237 (Div. 2) / 404C Restore Graph (构造最短路径树)

http://codeforces.com/contest/404/problem/C 思路:我们构造一颗最短路径树就行了。 若能够构造,边数必然为n-1(样例1的边数可以是两条)。 如何构造?从距离为1的点开始,逐渐往下加边,生成一颗k叉树。若在中间生成了大于k的叉,则输出-1。 完整代码: /*265ms,4436KB*/ #include using namesp

AC,∑ndless 1840

Codeforces Round #186 (Div. 2) / 313B Ilya and Queries (字符串处理)

B. Ilya and Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ilya the Lion wants to help all his fri

AC,∑ndless 1810

【优化&大师级代码欣赏】Codeforces Round #137 (Div. 2) / 222B Cosmic Tables (矩阵)

B. Cosmic Tables http://codeforces.com/problemset/problem/222/B time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 1782

Codeforces Round #218 (Div. 2) / 371B Fox Dividing Cheese (想法题)

http://codeforces.com/contest/371/problem/B 神题必有神解——你能想到这么做吗? /*15ms,0KB*/ #include using namespace std; int op_cnt[6]; int main() { int a, b, ans = 0; cin >> a >> b; for (int n = 2; n <=

AC,∑ndless 1696

视频隐私脱敏工程化:CSRT/KCF追踪算法在本地推理中的实现与边界

在短视频内容合规审查中,动态遮挡(Dynamic Masking)是高频且高耗时的环节。传统手动关键帧打码不仅效率低下,且在目标快速移动或遮挡时极易出现遮罩漂移。本文从计算机视觉工程角度,解析基于CSRT与KCF算法的目标追踪方案在视频隐私处理中的技术路径、性能权衡及落地实践。

Mysssone的博客 189

【算法拾光】链表 哈希表|K个一组翻转链表 + 两数之和

K个一组翻转链表需分段反转,借助哑节点与前驱指针维护连接,避免断链;两数之和利用哈希表实现O(1)查找,空间换时间,高效定位目标组合。前者考察链表指针操作,后者聚焦映射关系构建,均为面试高频题。

wuqingyigexiaoba的博客 288

排序算法深度笔记(下):非比较类排序的线性突破与工程边界

排序算法时间复杂度额外空间复杂度稳定性是否基于比较选择排序O(N^2)(O(1))不稳定是冒泡排序O(N^2)(O(1))稳定是插入排序O(N^2)(O(1))稳定是归并排序O(N\log N)(O(N))稳定是快速排序O(N\log N)O(log N)不稳定是堆排序O(N\log N)O(1)不稳定是计数排序(O(N + M))O(M))稳定否基数排序O(N)稳定否桶排序平均O(N) / 最坏O(N^2)

2401_87069538的博客 559
上一篇: 汇编端口及其作用详细列表
下一篇: Codeforces Round #198 (Div. 2) / 340B Maximal Area Quadrilateral (点集中的最大四边形)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值