NOJ [1317] Exercise of Sort

浪潮java笔试大题 第一题石头 求最少操作多少次使得石头升序排列 只需求出最大递增1的子序列长度,再用总长度减去子序列长度 package 浪潮编程; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int num = 1, max = 1; int tree = in.nextInt(); if (tree 阅读详情
链接地址:http://ac.nbutoj.com/Problem/view.xhtml?id=1317

线段树
如果是按照顺序来寻找位置的话,会发现遗漏了许多的信息。
所以,我们应该反过来寻找位置!

出题代码:

#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;

#define maxn 201000
#define lson rt << 1
#define rson rt << 1|1
int sum[maxn * 4];
int val[maxn];
int rank[maxn];
int pos[maxn];
int a[maxn];
int n;

void pushup(int rt)
{
sum[rt] = sum[lson] + sum[rson];
}

void build(int rt, int l, int r)
{
if (l == r)
{
sum[rt] = 1;
return;
}
int m = (l + r) >> 1;
build(lson, l, m);
build(rson, m + 1, r);
pushup(rt);
}

void insert(int rt, int l, int r, int pos, int val)
{
if (l == r)
{
sum[rt] += val;
return;
}
int m = (l + r) >> 1;
if (pos <= m) insert(lson, l, m, pos, val);
else insert(rson, m + 1, r, pos, val);
pushup(rt);
}

int query(int rt, int l, int r, int val)
{
if (l == r)
{
if (sum[rt] == val) return l;
else return l - 1;
}
int m = (l + r) >> 1;
if (sum[lson] <= val) return query(rson, m + 1, r, val - sum[lson]);
else return query(lson, l, m, val);
}

int main()
{
//freopen("data.in", "r", stdin);
//freopen("data.out", "w", stdout);
while (~scanf("%d", &n))
{
memset(val, 0, sizeof(val));
memset(rank, 0, sizeof(rank));
for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &val[i]);
build(1, 1, n);
for (int i = n; i >= 1; i--)
{
int t;
t = query(1, 1, n, a[i]);
pos[i] = t + 1;
insert(1, 1, n, pos[i], -1);
}
for (int i = 1; i <= n; i++) rank[pos[i]] = i;
for (int i = 1; i <= n; i++)
{
if (i - 1) printf(" ");
printf("%d", val[rank[i]]);
}
printf("\n");
}

return 0;
}

数字政府政务服务AI大模型赋能智能体平台及AI场景应用规划方案(决策评审版).pptx 立即下载

相关推荐

T18_低空经济示范区十五五通感一体化低空智联网与飞行服务保障体系设计方案_生态合作版.pptx

T18_低空经济示范区十五五通感一体化低空智联网与飞行服务保障体系设计方案_生态合作版.pptx

NYOJ 373 石子合并(一)

题目链接~~> 做题感悟:刚开始想到这题和矩阵连乘的方法类似,但是没有推出方程! 解题思路:动态方程:dp[ i ] [ j ] = min ( dp[ i ] [ k ] +dp [ k+1 ] [ j ] + sum[ i ] - sum[ i-1 ] +sum[ j ] - sum[ k ] ) ( i 代码: #include #include #include #include

Muti-Agent 1809

Bulk / Smart-seq2数据分析一般流程

Bulk RNA-seq(RNA-Seq of bulk samples)是一种RNA-Seq技术应用,它是通过将整个组织或细胞群体的RNA提取并混合,进行高通量测序来分析基因表达的技术。转录本定量结果可以用于后续的差异表达分析和聚类分析。功能注释和富集分析:对差异表达基因进行功能注释和富集分析,以帮助理解差异表达基因的功能和调控网络,从而获得对研究样品的更深入的理解。数据可视化:最后,将聚类分析的结果进行可视化,可以使用常见的数据可视化工具,如ggplot2、Plotly等,来帮助用户更好地理解数据。

weixin_54519672的博客 5353

NOJ 1317——Exercise of Sort

问题描述Wodex opened the door successfully. At the same time, horn sounded: If you are not clever, the game will be so boring, next level will be more difficult. Ha-ha-ha... So, Wodex came in with his par

Alex 534

基于TDOA的chan算法(定位算法)

Chan算法原理 TDOA(TDOA,the time differences of arrival,到达时间差),Chan算法是TDOA定位方法的一个很好用的方法。 Chan算法是非递归双曲线方程组解法,具有解析表达式解,主要特点是:在测量误差服从理想高斯分布时,它的定位精度高、计算量小,并且可以通过增加已确定点的数量来提高算法精度。 该算法的推导前提是基于测量误差为零均值高斯随机变量,对于实际环境中误差较大的测量值,比如在有非视距误差的环境下,该算法的性能会有显著下降。二维情况下,可分为只有三个点参与定

优快云不再更新 2万+

ImageNet分类实战:用PyTorch复现AlexNet的5个关键技巧(附代码)

本文详细介绍了使用PyTorch复现经典AlexNet模型进行ImageNet图像分类的五个关键工程技巧。内容涵盖模型架构的现代重构、训练策略优化、核心组件实现与替代方案,以及实用的训练调试方法,并提供了完整的代码示例,帮助开发者深入理解深度卷积神经网络的实现细节与优化思路。

i0j1k2l3m的博客 95

ACM第K大数——双二分

数组A和数组B,里面都有n个整数。数组C共有n^2个整数,分别是A[0] * B[0],A[0] * B[1] ......A[1] * B[0],A[1] * B[1]......A[n - 1] * B[n - 1](数组A同数组B的组合)。求数组C中第K大的数。

ColorWaterer的专栏 1716

新手必看:5分钟搞定Unitree Go1机器狗Gazebo仿真运动控制(附按键图解)

本文为新手提供了Unitree Go1机器狗在Gazebo仿真环境中实现运动控制的快速指南。通过5分钟极简配置和按键图解,帮助开发者快速掌握宇树科技明星产品的基础操作,包括环境搭建、仿真启动和运动控制技巧,适合零基础用户快速上手。

weixin_42550597的博客 301

ACM投票——二分法

问题描述 有N个城市,每个城市有Ai个人。 现在要开始投票,每个人有一张票。 作为领导者,你有B个箱子,你必须要将这B个箱子分发到N个城市去,每个城市至少需要一个箱子。 每个人都必须要投票,不能弃票,也就是说要把票丢进箱子里去(每个城市有Ai张票)。

ColorWaterer的专栏 1576

GAMIT/GLOBK 10.71在Linux环境下的GNSS数据处理全流程解析(附实战案例)

本文详细解析了在Linux环境下部署和运行GAMIT/GLOBK 10.71进行GNSS数据处理的完整流程。从系统环境配置、软件编译安装、关键表格文件更新,到运行自带示例和实战案例,提供了清晰的步骤与避坑指南,帮助用户掌握这一高精度GNSS数据处理工具的核心使用方法。

kmeans3miner的博客 311

ResNet改进(7):添加 SK注意力机制

实现 SK 注意力机制。

2401_82355416的博客 732

NOJ [1314] Brave Sword

链接地址:http://ac.nbutoj.com/Problem/view.xhtml?id=1314是不是想起了筷子大作战这一题?(1) 那题的意思就是有很多筷子,除了其中一只,其他都是成对等长出现的。直接异或,所有相同的数都会被抵消(异或运算中,相同位置值相等的结果为0,就是说所有成对出现的都会最终成为0),最后的结果自然是那个落单的数了。然后,我们来看这题。(2) 这题的意思是有很多把钥匙

ColorWaterer的专栏 944

Unitree G1仿人机器人协同搬箱:从仿真搭建到多机协同部署完整指南

Unitree G1仿人机器人协同搬箱技术方案摘要 本文提供了一套完整的Unitree G1人形机器人协同搬箱解决方案,涵盖从仿真环境搭建到多机协同部署的全流程。核心内容包括: 双仿真环境配置:同时搭建Gazebo+ROS Noetic基础仿真环境与Isaac Gym+Mujoco高性能RL训练环境,支持Sim2Sim迁移验证 训练框架搭建:详细配置unitree_rl_gym框架,提供PPO算法定制化训练流程和参数优化方案 数据集应用:整合宇树开源真机数据集(UnifoLM-WBT-Dataset)~~~

huanghm88的专栏 477

ACM 寻找众多情侣堆中的两个基佬

这题的意思是有很多情侣,每对情侣手握的牌号是一样的,然后在这群人中,有两个人是搞基的,他们手里握的牌子是不一样的,请找出这两个人,并从小到大输出他们的牌号。

ColorWaterer的专栏 794

【QNX Hypervisor 2.2 用户手册】2.6 处理qvm终止

你可以注册通知,以在qvm进程实例退出时得到通知。这样你就可以采取相应的措施来响应这种终止事件。

从0到1,突破自己 1109

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

NOJ [1313] Anger Begins

链接地址:http://ac.nbutoj.com/Problem/view.xhtml?id=1313线段相交 + 并查集线段斜率可以是0也可以是无穷大。只要有一条路的一个点在另一条路上就算连通。将连通的路并在一起,然后直接就可以判断了。出题代码:#include #include #include #include #include #include #include #include #in

ColorWaterer的专栏 676

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

NOJ 1175 Dress, Left Dress!

链接地址:http://ac.nbutoj.com/Problem/view.xhtml?id=1175一些士兵站在一直线上,当每一个人都向左看时,看到的第一个比自己高的那个人就是the first man。并输出the first man的位置,若不存在the first man,输出-1。将所有身高存在一数组里,然后遍历一遍,但是这样会超时!所以,必须要优化算法。 这些身高中,如果一人的

ColorWaterer的专栏 658

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

NOJ [1201] Chihuo II - Eating in China

链接地址:http://ac.nbutoj.com/Problem/view.xhtml?id=1201这题其实不难,总归算法就是凸包加水DP。但是我一直RA,以为是凸包码错了,还新学了一个凸包的算法,发现又错了,最后才知道是忘了初始化。题目意思很容易理解,就是洛天依去中国吃好吃的,然后经过了N个地方,每个地方都有坐标x和y表示。洛天依游走的方法是独特的,她一定要先在最外面一圈的点找一个点开始出发

ColorWaterer的专栏 650

NOJ 1002 将军问题

连接地址: http://ac.nbutoj.com/Problem/view.xhtml?id=1002 在做此题之前,你首先要知道中国象棋的游戏规则吧,不知道的看说明书去。 问题很简单,就是让你判断当时的局面是否存在将军状态。 首先,我们先想想,可以产生将军的棋子是哪些? 兵提步,判断将帅周围的三格是否有对方的兵。 炮跳轰,判断将帅所在的两条坐标线上是否有对方的炮,且将帅与炮中间必须

ColorWaterer的专栏 636

HDU 1405 坑爹的The Last Practice

链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1405此题真坑!!!题意很容易就能看懂,坑爹的地方就在“每个数字后都有一个空格,包括最后一个数字”。以下是我AC的代码:#include #include #include #include #include #include #include #include #include #include #i

ColorWaterer的专栏 633

杭电 1212 Big Number

链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1212以下是我AC的代码。#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#d

ColorWaterer的专栏 611

NOJ [1016] 缙云烧饼

链接地址:http://ac.nbutoj.com/Problem/view.xhtml?id=1016突然发现自己刚进入ACM队时写的一个代码,现在还是觉得好好笑,翻出来晒晒。#include using namespace std;#define N 1000char a[N][N];int main(){    int n,m,i,j,s;    while (scanf("%d",&n)!

ColorWaterer的专栏 611

NOJ [1318] First Choice

链接地址:http://ac.nbutoj.com/Problem/view.xhtml?id=1318此题就是一个欧拉回路。将每一个房间都理解为一个点,然后门就是房间间的连接条件,门的个数就是该点的度,只要所有点的度出现奇数的次数小于3就表示可以走完所有的连接且不重复。那么还有一个条件就是先判断此图是否是完全连通的。DFS一下就可以了。出题代码:#include #include #includ

ColorWaterer的专栏 578

NOJ [1319] Go Through

链接地址:http://ac.nbutoj.com/Problem/view.xhtml?id=1319此题的意思就是,Wodex和他的一个伙伴要经过所有的圆盘(点),他们所走的距离要在M内,所以肯定要求最短路。起先他们可以各自选择一个点作为起始点,然后开始走。然后走的方式是这样的,走过最外面一圈的任意一点的那个人就不能走除最外面那些点以外的点(我们称这些点为内点好了)了,而且Wodex的伙伴因为

ColorWaterer的专栏 573

HDU 1202 The calculation of GPA

链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1202此题非常好理解,代码也很好敲,但是有很多坑。首先,学分和分数都是double型的(分数可以大于100,更可以小于0)=  =其次,分数为-1的,算缺考(但是如果所有科目都是缺考的话,要输出-1、下面是我AC的代码:#include #include #include #include #inclu

ColorWaterer的专栏 570

NOJ [1321] I am You

链接地址:http://ac.nbutoj.com/Problem/view.xhtml?id=1321给你一个N,让你找到最小的M使得(2 ^ N - 1) % (2 ^ M - 1) = 0。2 ^ N的二进制数一定是1后面跟随一些0,那么2 ^ N - 1的二进制数每一位上都是1了,所以要想使(2 ^ N - 1) % (2 ^ M - 1) = 0, 那么其实只要使2 ^ N - 1的二进

ColorWaterer的专栏 550
上一篇: NOJ [1316] D Minimums of Sum
下一篇: NOJ [1318] First Choice
ColorWaterer
博客等级 码龄12年 16粉丝 128原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值