POJ 重要逆序对

【算法】重要逆序对-分治法 数据结构与算法 阅读详情

总时间限制:  10000ms       单个测试点时间限制: 1000ms

 

内存限制:    65536kB

描述

给定N个数的序列a1,a2,...aN,定义一个数对(ai, aj)为“重要逆序对”的充要条件为 i < j 且 ai > 2aj。求给定序列中“重要逆序对”的个数。

输入

第一行为序列中数字的个数N(1 ≤ N ≤ 200000)。
第二行为序列a1, a2 ... aN(0 ≤a ≤ 10000000),由空格分开。

输出

输出一个整数,为给序列中“重要逆序对”的个数。

样例输入

10
0 9 8 7 6 5 4 3 2 1

样例输出

16

提示

如果使用printf输出long long类型,请用%lld
数据范围
对于40%的数据,有N ≤ 1000。

 

本题的典型解法是采用归并排序。相似题目为“求逆序对数”。

在"求逆序对数"中,归并排序的核心代码如下

void merge(int *s, int *temp, int startIndex, int endIndex, int mid)
{
    int i = startIndex, j = mid + 1, k = startIndex;
    int pointer = startIndex;

    while(i <= mid && j <= endIndex)
    {
        if(s[i] > s[j])
        {
            temp[k] = s[j];
            sum += mid - i + 1;//sum表示逆序对数
            j ++;
        }
        else
        {
            temp[k] = s[i];
            i ++;
        }
        k ++;
    }

    while(i <= mid)
    {
        temp[k ++] = s[i ++];
    }
    while(j <= endIndex)
    {
        temp[k ++] = s[j ++];
    }
    for(int i = startIndex; i <= endIndex; i ++)
    {
        s[i] = temp[i];
    }

}

但是本题所求为“重要逆序对数”,因此我在上机时的做法如下:

void merge(int *s, int *temp, int startIndex, int endIndex, int mid)
{
    int i = startIndex, j = mid + 1, k = startIndex;
    int pointer = startIndex;

    while(i <= mid && j <= endIndex)
    {
        if(s[i] > s[j])
        {
            temp[k] = s[j];

            if(s[i] > 2 * s[j])
                sum += mid - i + 1;
            else
            {
                 for(int t = i + 1; i <= mid; i ++ )
                {
                    if(s[t] > 2 * s[j];
                    {
                        sum += mid - t + 1;
                        break;
                    }
                }  
            }

            j ++;
        }
        else
        {
            temp[k] = s[i];
            i ++;
        }
        k ++;
    }

    while(i <= mid)
    {
        temp[k ++] = s[i ++];
    }
    while(j <= endIndex)
    {
        temp[k ++] = s[j ++];
    }
    for(int i = startIndex; i <= endIndex; i ++)
    {
        s[i] = temp[i];
    }

}

但是很不幸的是,TLE了。回来后,室友提醒,在里面加了一重循环后,时间复杂度就不是O(nlogn)了,在最坏情况下,应该是O(n^2 logn)。上机时信心满满地以为加了break应该不会TLE,但是...

室友的做法是建立一个虚拟指针pointer,从startIndex开始,一直指到mid结束。时间复杂度并不会增加。

譬如归并(0, 6, 7, 8, 9)和(1, 2, 3, 4, 5)时,s[i]指向左边部分,s[j]指向右边部分。当pointer指向6,s[j] = 1 时,2 * 1<6;因此6右边的7,8,9都是重要逆序;pointer指向6,s[j] = 2时,2 * 2 < 6;因此,6右边的7,8,9都是重要逆序;pointer指向6,s[j] = 3时,2 * 3 = 6,因此需要加pointer右移一位,此时pointer指向的是7,2 * 3 < 7,因此 7右边的8,9都是重要逆序......以此类推,对于每一个s[j],都将pointer移动至s[pointer] > 2 * s[j]的位置i处。

显然pointer最多只需要移动 n / 2次(从startIndex到mid处),因此不会增加复杂度。

完整代码如下:

#include <iostream>

using namespace std;

long long sum = 0;


void merge(int *s, int *temp, int startIndex, int endIndex, int mid)
{
    int i = startIndex, j = mid + 1, k = startIndex;
    int pointer = startIndex;

    while(i <= mid && j <= endIndex)
    {
        if(s[i] > s[j])
        {
            temp[k] = s[j];

            while(s[pointer] <= 2 * s[j] && pointer <= mid)
            {
                pointer ++;
            }
            if(pointer != mid + 1)
            {
                sum += mid - pointer + 1;
            }

            j ++;
        }
        else
        {
            temp[k] = s[i];
            i ++;
        }
        k ++;
    }

    while(i <= mid)
    {
        temp[k ++] = s[i ++];
    }
    while(j <= endIndex)
    {
        temp[k ++] = s[j ++];
    }
    for(int i = startIndex; i <= endIndex; i ++)
    {
        s[i] = temp[i];
    }

}

void mergeSort(int *s, int *temp, int startIndex, int endIndex)
{
    int mid = (startIndex + endIndex) / 2;

    if(startIndex < endIndex)
    {
        mergeSort(s, temp, startIndex, mid);
        mergeSort(s, temp, mid + 1, endIndex);
        merge(s, temp, startIndex, endIndex, mid);
    }
}


int s[200005] = {};
int temp[400010] = {};

int main(){

    int n;
    cin >> n;
    for(int i = 0; i < n; i ++)
    {
        cin >> s[i];
    }
    mergeSort(s, temp, 0, n - 1);
    cout << sum << endl;
    return 0;
}

如果代码有问题,还望指出。

POJ 16453 重要逆序对|归并排序 题目描述 总时间限制:1000ms 内存限制:256000kB 描述 给定N个数的序列a1,a2,...aN,定义一个数对(ai, aj)为“重要逆序对”的充要条件为 i < j 且ai> 2aj。求给定序列中“重要逆序对”的个数。 输入 本题有多个测试点,每个测试点分为两行:第一行为序列中数字的个数N(1 ≤ N ≤ 200000),第二行为序列a1, a2 ... aN(0 ≤a ≤ 10000000),由空格分开。N=0表示输入结束。 输出 每个测试点一行,输出一个整... 阅读详情

相关推荐

【分治策略】逆序对问题总结

一、逆序对1. 问题背景假如有一组电影集合,包括n部电影。某个人对这n部电影的喜欢程度各有高低,根据其喜欢程度对这n部电影进行排名,按照从1到n的方式进行标记,这就形成了一个关于电影的排名表。假设你和一个陌生人各有自己对于这n部电影的排名表。现在想要比较你跟这个陌生人的“品味”差别,看看你们俩是否有“类似”的爱好。一个很自然的办法就是对比两个人各自的排名表,看看两个排名表的排名状况是否相似。如果两张

hongchh的博客 1万+

计算逆序数对&&重要逆序数对(significant inversion)

文章目录逆序数对简介计算逆序数对思路significant inversion 简介significant inversion 思路significant inversion 代码 逆序数对简介 数组中的两个元素A[i], A[j],如果下标 i < j,但 A[i] > A[j] ,称 A[i] 与 A[j] 为逆序数对 计算逆序数对思路 Divide and Conquer ......

haiki66的博客 1315

[逆序对] poj 2893 M × N Puzzle

/** [逆序对] poj 2893 M × N Puzzle 某状态的奇偶性定义为逆序对(不包括0的)总数的奇偶性。 此题目终态为偶数 首先,0的左右移动不改变奇偶性。 N为奇数,上下移动不改变奇偶性,故逆序数为偶的YES N为偶数,上下移动逆序数变化为±1,此时还要考虑0的竖直距离,逆序数%2 == 距离%2 时YES */ #include #include #define lowbi

Mr.CJ 2170

算法课7-Divide and Conquer

分治的思想,最经典的两个例子首先是排序的两个例子 一个是快排 一个是归并排序【请看到这里的你,去复习一下排序算法】 【这里填充快排和归并排序代码】 ...

srping123的博客 689

逆序对实现

实现了高级数据结构里面的课后习题逆序对,采用的语言是c

算法-求排列的逆序数(信息学奥赛一本通-T1237).rar

算法-求排列的逆序数(信息学奥赛一本通-T1237).rar

逆序对 POJ2299

逆序对POJ2299 思路 题干在这:POJ2299 我们采用归并排序的方法,边排序边统计逆序对,输出即可。注意边界条件。 有一个坑就是最后的结果超过int范围,我提交WA,还是看了别人的题解才知道是这里有问题…… ac代码 #include<stdio.h> #include<iostream> using namespace std; int in[500001] = ...

没有自旋的π介子 214

银河麒麟系统下VSCode安装全攻略:从下载到桌面快捷方式(附常见问题解决)

本文详细介绍了在银河麒麟系统下安装和优化VSCode的全流程,包括环境准备、安装策略、权限管理、桌面快捷方式创建以及系统级性能调优。特别针对国产系统环境提供了常见问题解决方案和必备插件推荐,帮助开发者高效配置开发环境。

v6b7n8m9q0的博客 1140

线段树求逆序对(POJ2299)

POJ2299 逆序对即给定一行序列,问对于每一个数字,位于该数字前面且大于该数字的共有多少个。 事实上,我们可以建立一个哈希表,把输入的数字全部统计进去,每计算一个数字的逆序数时,统计该数字后面的值之和,例如: 5 3 7 4 1 建立哈希表:m[1],m[3],m[4],m[5],m[7] 初始都是0 现在加入5,则m[5]++,统计m[5]后面的数(m[7])之和为0 加入3,则m[3...

September_的博客 432

实验六 有源滤波器

实验六 有源滤波器一、实验目的二、仪器及设备三、预习要求画出三个电路的幅频特性曲线。四、实验内容l.低通滤波电路2.高通滤波电路3.带阻滤波电路(1)实测电路中心频率。(2)以实测中心频率为中心,测出电路幅频特性。五、实验报告六,仿真图:图 1 低通滤波器仿真图图 2 高通滤波器仿真图图 3 带阻滤波电路仿真图 一、实验目的 1.熟悉有源滤波电路构成及其特性。 2.学会测量有源滤波电路幅频特性。 二、仪器及设备 1.示波器 2.信号发生器 三、预习要求 1.预习教材有关滤波电路

胡毛毛的博客 1万+

概率论—期末复习速成笔记(自用)

概率论期末复习

a200327的博客 2万+

poj 1804 Brainman(求逆序对)

Description Background  Raymond Babbitt drives his brother Charlie mad. Recently Raymond counted 246 toothpicks spilled all over the floor in an instant just by glancing at them. And he can even c

ZAQ的博客 1018

《FreeRTOS 入门与实战》第2章:开发环境搭建(实战)

STM32CubeIDE工程创建与FreeRTOS移植J-Link调试环境搭建SystemView可视化跟踪配置。

2301_79143213的博客 1738

POJ2299 Ultra-QuickSort 逆序对

题目链接 http://poj.org/problem?id=2299 分析 每次交换均可消除一个逆序对,最终目标逆序对数为 000,故该问题等价于求解给定序列逆序对数。 AC代码 #include <cstdio> inline int read() { int num = 0; char c = getchar(); while (c < '0' || c > ...

Kevin的博客 183

使用DrissionPage实现携程酒店信息智能爬取

本文介绍了一个基于DrissionPage技术的携程酒店信息爬虫系统,通过监听API数据包实现高效采集。系统可自动获取酒店名称、价格、评分、位置等15个维度的数据,支持多页滚动加载和智能去重。相比传统爬虫,该方法直接解析API返回的JSON数据,避免了复杂的HTML解析和加密参数分析,提高了开发效率和稳定性。文章详细阐述了13个关键实现步骤,并强调数据采集应严格遵守法律法规,仅用于技术学习和市场研究。该系统可为旅游决策、价格监测等提供数据支持,但需注意合理使用频率和隐私保护。

那些看似不起波澜的日复一日,会在某天让你看到坚持的意义 394

基于YOLOv8的农作物病虫害检测系统设计与实现

国内如中国农业大学的科研团队采用改进的Faster R-CNN模型对小麦病害进行检测,取得了较好的效果。农作物病虫害是影响农业生产的重要因素之一,每年因病虫害导致的农作物减产高达20%-40%。YOLO(You Only Look Once)系列算法作为目标检测领域的代表性模型,以其高效、准确的特点在众多领域得到广泛应用。YOLOv8作为该系列的最新版本,在精度和速度上都有显著提升,非常适合农作物病虫害检测这类需要实时处理的应用场景。然而,现有研究仍存在一些不足:一是模型复杂度高,难以部署到移动设备;

YOLO 798

树状数组求逆序对:POJ 2299、3067

  前几天开始看树状数组了,然后开始找题来刷。   首先是 POJ 2299Ultra-QuickSort:http://poj.org/problem?id=2299   这题是指给你一个无序序列,只能交换相邻的两数使它有序,要你求出交换的次数。实质上就是求逆序对,网上有很多人说它的原理是冒泡排序,可以用归并排序来求出,但我一时间想不出它是如何和归并排序搭上边的(当初排序没学好...

aidiao7379的博客 154

SAP 物料主数据 Forecasting 视图,别把预测只当成一个数字字段

摘要(150字): SAP S/4HANA物料主数据的Forecasting视图常被忽视,但对依赖历史消耗规律的物料至关重要。该功能基于工厂维度的历史消耗数据,结合预测参数自动计算未来需求,动态调整重订货点和安全库存。预测模板(Forecast Profile)能标准化参数设置,而消耗数据(Consumption Values)的质量直接影响预测结果。预测值作为MRP输入,需注意保存操作才能生效。自动重订货点功能通过分析消耗波动和服务水平,实现库存策略的动态优化。Individual Forecast功能则

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1448

POJ 2299(归并求逆序对)

POJ 2299(归并求逆序对) POJ 2299 #include <cstdio> #include <cstring> using namespace std; typedef long long ll; const int N = 5e5+10; int n; ll cnt; int s[N], a[N], tmp...

qq_37804582的博客 179

海洋捕食者算法(MPA)详解:从海洋生态智慧到高性能优化

摘要: 海洋捕食者算法(MPA)是一种基于海洋生态觅食行为的元启发式优化算法,模拟捕食者(如鲨鱼)的布朗运动和莱维飞行策略进行全局与局部搜索。算法分为三阶段:高速比阶段(全局探索)、单位速度比阶段(平衡搜索)和低速比阶段(局部开发),通过精英矩阵和FADs效应(概率扰动)避免早熟收敛。MPA具有参数少、收敛快、寻优能力强等特点,适用于复杂优化问题,其数学模型将生物行为转化为随机游走与自适应策略,并通过收敛因子动态调整探索-开发平衡。实验表明,MPA在多个基准问题上表现优异。

qq_42212808的博客 276

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

树状数组求逆序对 poj2299

树状数组求逆序对; 对于一组任意顺序的数,记下他们的初位置,再进行排序,记下他们本来应该在的位置。然后,按最初位置从前往后,进行处理。 基本思想: 对于一个数要求它对应得逆序对,可以通过求前面小于等于它的数的个数,然后用当前已处理的数的个数-前面小于等于当前的数的个数得到。 如: 4 3 5 2 1 排序后 1 2 3 4 5 对于第一个数4,当前处理数的个数为1,本来应该在的位置是4,则在第4个...

weixin_43184669的博客 207

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

BIT应用 逆序对 POJ2299

/* POJ2299 BIT+逆序对 by sbn 2018-1-12*/ /* 5 9 1 0 5 4 3 1 2 3 0 */ #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<vector> #include<algorithm> #define

u014681071的博客 241

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

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

逆序对问题小计-爆搜,分治(Poj 1007,洛谷 P1908 逆序对)

求逆序对是一个经常遇到的问题,很久之前做过一道,今天又遇到一个类似的,用了大半个小时才把分治写好,写篇文章记录一下。 典型题-Poj 1007 爆搜 这道题由于数据范围很小,简单的暴力搜索也可以AC。对字符串中每一个字符,都要遍历其后的所有字符,统计逆序对,O(n2)O(n^2)O(n2) #include<iostream> #include<cmath> #inclu...

csyifanZhang的博客 273

poj3067 树状数组解决二维逆序对

一直在学习二维逆序对的解决方法,然后并没有搞明白,这是第一道自己搞出来的模板题。 POJ3067 JAPAN 题解: 设东部的城市为eie_iei​,西部的城市为wiw_iwi​,那么如果连接e1e_1e1​w2w_2w2​和连接e2e_2e2​w1w_1w1​的两条道路想形成交叉,必然有当e1&lt;e2e_1 &lt; e_2e1​<e2​时,w1&gt;w2w_...

__surtr的博客 494

POJ2299逆序对模板(树状数组)

题目:http://poj.org/problem?id=2299 只能相邻两个交换,所以交换一次只会减少一个逆序对。所以交换次数就是逆序对数。 ps:原来树状数组还可以记录后边lowbit位的部分和。见代码。 #include<iostream> #include<cstdio> #include<cstring> #include<al...

weixin_34004576的博客 139

poj3067 Japan 树状数组求逆序对

题目链接:http://poj.org/problem?id=3067 题目就是让我们求连线后交点的个数 很容易想到将左端点从小到大排序,如果左端点相同则右端点从小到大排序 那么答案即为逆序对的个数 用树状数组求解逆序对 代码: 1 #include<iostream> 2 #include<cstdlib> 3 #include<cstdi...

weixin_30508241的博客 85
上一篇: 计算两个日期之间的天数
mrvector
博客等级 码龄10年 7粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值