[codevs1540]银河英雄传说

手把手教你用Zemax优化MTF:从‘离焦平衡球差’到高频像差控制的实战技巧 本文详细介绍了如何使用Zemax优化MTF性能,从基础设置到高级技巧的全流程。通过具体案例,讲解了如何利用离焦平衡球差提升中频MTF,以及识别和控制高频像差的方法,帮助光学设计工程师和学生有效提升成像质量。 阅读详情

“我们的征途是星辰大海”

银英传←

这才是题目←

思路:
加权并查集
维护f[i],t[i],cnt[i]
cnt[i]->i在当前队列中后面有多少元素
f[i]->i所在集合标志元素(队列底元素)
注意在未执行find(i)操作时,f[i]不一定为i真正的底
t[i]->i所在队列顶元素
t[i]仅在merge更新不再是队底的元素的cnt值时有意义
需要保证每个元素的f[i]的t、cnt等值时刻为实际值,这样每个元素在find后,t、cnt等可更新为实际值
有点像线段树的lazy思想?

/*
4

M 2 3

C 1 2

M 2 4

C 4 2
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 200000 + 50;
int f[MAXN],t[MAXN],cnt[MAXN];
void init(int n)
{
    for(int i = 1;i <= n;i ++)
        f[i] = i,t[i] = i;
}
int n;
int find(int x)
{
    if(x == f[x])return x;
    int fa = f[x];
    f[x] = find(f[x]);
    cnt[x] += cnt[fa];
    return f[x];
}
void merge(int a,int b)
{
    a = find(a);b = find(b);
    find(t[b]);//t[b]不为标志元素,其值不一定为实际值
    cnt[a] = cnt[t[b]] + 1;
    f[a] = b;
    t[b] = t[a];
}
char ch;
int x,y;
int main()
{
    cin >> n;
    init(30000);
    for(int i = 1;i <= n;i ++)
    {
        cin >> ch >> x >> y;
        if(ch == 'M')
        {
            merge(x,y);
        }
        else 
        {
            find(x);find(y);
            if(f[x] != f[y])
            {
                cout << -1 << '\n';
            }
            else
            {
                if(cnt[x] < cnt[y])swap(x,y);
                cout << cnt[x] - cnt[y] - 1 << '\n';
            }
        }
    }
} 

好像18年要重新动画化?emmmmm

C++继承与多态 - 继承多态原理01 C++继承多态原理讲解 阅读详情

相关推荐

保姆级教程:用GMT6.1绘制专业地形起伏图(从数据下载到出图避坑)

本文提供了一份详细的GMT6.1绘制地形起伏图的保姆级教程,从环境搭建到数据下载,再到核心绘图命令解析,帮助用户避开常见错误。特别适合科研人员和地理信息爱好者快速掌握专业地形图的绘制技巧,提升工作效率。

weixin_42549723的博客 277

【codevs1540】 银河英雄传说

题解 我们可以把战场的每一列看作一个集合,初始时每个集合中只有一个元素。M指令可以看作合并集合,这令我们想到并查集。定义father数组,s数组和sum数组,分别表示并查集中每个元素的父亲,距自己的父亲的距离和该集合中的元素个数。只需要合并和路径压缩的时候注意一下就可以了。C指令可以利用类似前缀和的思想。

zhuml123的专栏 680

大数据之父_BIM先驱Charles (Chuck) M. Eastman逝世——致敬“BIM之父”

原标题:BIM先驱Charles (Chuck) M. Eastman逝世——致敬“BIM之父”BIM研究的先驱、佐治亚理工教授Charles (Chuck) M. Eastman于本周一(11月9日)在其Atlanta家中逝世。特转韩国Yonsei大学Ghang Lee教授的讣文以作纪念。过世原因未说明。BIM的出现是与当今时代科技的发展分不开的。在信息时代建筑发展面临的挑战巨大:建筑物越建越高...

weixin_39941262的博客 3302

Codevs1540银河英雄传说

http://codevs.cn/problem/1540/ 思路 要加深对并查集的理解#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; int t,a,b; int fa[100010],pos[100010],sum[100010];//pos相对深度,su

东隅已逝,桑榆非晚~Loi_MurasameKatana 534

保姆级教程:在Ubuntu 22.04上用Conda搞定nuPlan数据集环境(Python 3.9 + PyTorch)

本文提供了一份详细的Ubuntu 22.04环境下使用Conda配置nuPlan自动驾驶数据集的保姆级教程,涵盖Python 3.9安装、Conda环境管理、PyTorch配置及数据集可视化验证等关键步骤,帮助开发者高效搭建开发环境。

weixin_29061997的博客 255

微信聊天记录丢失原因与恢复方案详解

SQLite数据库作为移动应用常见的本地存储方案,其加密机制和存储结构直接影响数据安全性。以微信为例,聊天记录存储在EnMicroMsg.db等SQLite文件中,采用AES加密保护。当手机清理工具误删这些文件时,会导致特定时间段记录丢失。理解数据恢复原理需要掌握文件系统删除机制和闪存特性,其中关键点包括TRIM指令的影响和数据块覆盖风险。通过专业工具如DiskDigger或iMyFone D-Back,配合ADB调试和SQLite数据重组技术,可在黄金时间窗口内恢复记录。日常维护建议结合自动化备份方案和存

weixin_32612263的博客 386

Codevs1540银河英雄传说[并查集]

有的时候并查集在合并与查询时不仅要维护父亲,也要维护集合的大小、元素的细节关系等等。 这时候,OI前辈们就完善出了一个新的数据结构,加权并查集,下面这道题就是加权并查集的一个简单运用~ 银河英雄传说 题目链接 题目描述 Description 公元五八O一年,地球居民迁移至金牛座&alpha;第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展。 ...

bangwo9535的博客 210

COdevs 1540 银河英雄传说

1540 银河英雄传说  source:2002年NOI全国竞赛 时间限制: 1 s    空间限制: 256000 KB    题目等级 : 大师 Master 题目描述 Description 公元五八○一年,地球居民迁移至金牛座α第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展。     宇宙历七

苦鬼·。 360

ADS 2013安装教程

1.2013和2014安装过程是一样的,运行ads2013_06_shp_windows文件进行安装 2.点击“NEXT”。 3.选择I accept,然后点击“NEXT”。 4.选择“complete”,然后点击“NEXT”。 5.选择安装路径,最好默认安装路径,安装路径不要有中文,然后点击“NEXT”。 6.点击“NEXT”. 7.如下路径默认安装,然后点击“NEXT”。 8.点击“NEXT”。 ...

谢谢关注“小鱼教你模数电”,各平台同号 6009

遗传算法(Genetic Algorithm)详解与实现

遗传算法(Genetic Algorithm, GA)是受自然进化原理启发的一系列搜索算法。通过模仿自然选择和繁殖的过程,遗传算法可以为涉及搜索、优化和学习的各种问题提供高质量的解决方案。同时,它们类似于自然进化,因此遗传算法可以克服传统搜索和优化算法遇到的一些障碍,尤其是对于具有大量参数和复杂数学表示形式的问题。

盼小辉丶的博客 24万+

CODEVS 1540 银河英雄传说(并查集)

                                1540 银河英雄传说题目链接:http://codevs.cn/problem/1540/题目描述 Description公元五八○一年,地球居民迁移至金牛座&amp;alpha;第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展。    宇宙历七九九年,银河系的两大军事集团在巴米利恩星域爆发战争。泰...

sortmin的博客 325

EMC辐射整改常用的4种整改方法

例如,产品设计研发工程师们根据需求,设计出效果良好的滤波电路,置入产品I/O(输入/输出)接口的前级,可使因传导而进入系统的干扰噪声消除在电路系统的入口处;通过选择元器件和合理安排的电路系统,使干扰的影响减少。有些频率点是通过电路板上走线分布参数所决定的,通过前述方法不大有用,此类整改通过在走线中增加小的电感、电容、磁珠来改变电路参数结构,使其移到限值要求较高的频率点上。电线电缆的分类整理在电子设备中,线间耦合是一种重要的途径,也是造成干扰的重要原因,因为频率的因素,可大体分为高频耦合与低频耦合。

学海无涯的专栏 3124

Codevs 1540+洛谷1196 银河英雄传说

http://www.studyai.com/article/1383d28f

Mercury的博客 340

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

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

codevs 1540 银河英雄传说 并查集

1540 银河英雄传说 2002年NOI全国竞赛 时间限制: 1 s 空间限制: 256000 KB 题目描述Description 公元五八○一年,地球居民迁移至金牛座&alpha;第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展。 宇宙历七九九...

weixin_30328063的博客 146

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

AC日记——银河英雄传说 codevs 1540

1540 银河英雄传说 2002年NOI全国竞赛 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题解 题目描述Description 公元五八○一年,地球居民迁移至金牛座&alpha;第二行星,在那里发表银河联邦创立宣言,同年改元...

weixin_33828101的博客 117

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

【codevs 1540】银河英雄传说

sum[]以当前舰艇为首的队伍长度 s[]当前舰艇到根节点的距离#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; int n,sum[500005],s[500005],fa[500005],x,y; char a; int find(int x) {

AliceBuJu 282

【CodeVS 1540】银河英雄传说 2002年NOI全国竞赛

noi这么水? 很久没有自己不看题解A题了 ~~~~~~ 带权并查集! CodeVS的数据不合规定??有乱七八糟的字符?? 见我注释掉的读入!【刚又测试 洛谷用被注释掉的那一句也可以A 说明CadeVS数据不合规定! #include #include #include #include #include using namespace std; #define INF 10000000

sxb_201的博客 581

边带权的并查集--银河英雄传说 NOI2002/CODEVS1540

题干: 有一个划分成N列的星际战场,各列依次编号为1,2,…,N。有N艘战舰,也依次编号为1,2,…,N,其中第i号战舰处于第i列。 有M条指令,每条指令格式为以下两种之一: M i j,表示让第i号战舰所在列的全部战舰保持原有顺序,接在第j号战舰所在列的尾部。 C i j,表示询问第i号舰艇与第j号舰艇当前是否处在同一列中,如果在同一列中,他们之间隔了多少艘战舰。如果第i号战舰与第j号战舰当前...

hwdn3000的博客 380

【codevs 1540】银河英雄传说2002年NOI全国竞赛(并查集)

1540 银河英雄传说2002年NOI全国竞赛 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题目描述Description 公元五八○一年,地球居民迁移至金牛座&alpha;第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展。 宇宙历七九九年,银河系的两大军事集团在巴米利恩星域爆发战争。泰山压...

weixin_30363981的博客 76

#并查集#洛谷 1196 SSL 1225 codevs 1540 银河英雄传说

题目 求战舰间有多少个战舰。 分析 并查集 fro表示到队头有多少个船舰。 代码 #include &amp;amp;lt;cstdio&amp;amp;gt; #include &amp;amp;lt;cctype&amp;amp;gt; using namespace std; int t,f[30001],beh[30001],fro[30001],x,y; char k; int get

lemondinosaur的博客 262

poj 1988 Cube Stacking && codevs 1540 银河英雄传说(加权并茶几)

#include<iostream> #include<cstdio> #include<cstring> #define maxn 30010 using namespace std; int m,fa[maxn],top[maxn],num[maxn]; char s; int find(int x) { if(x==fa[x]...

weixin_30951389的博客 127

codevs 1051[NOI 2002]银河英雄传说

本博客给出了codevs 1051的代码

Leo的博客 1189
上一篇: [codevs1710]生日蛋糕
下一篇: [codevs1995]黑魔法师之门
LOI_pingxing
博客等级 码龄10年 24粉丝 103原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值