POJ 2085 Inversion

zoj1201--------Inversion Let { A1,A2,...,An } be a permutation of the set{ 1,2,..., n}. If i Aj then the pair (Ai,Aj) is called an "inversion" of the permutation. For example, the permutation {3, 1, 4, 2} has three inversion 阅读详情

 

Inversion
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 2631 Accepted: 1143

Description

The inversion number of an integer sequence a1, a2, . . . , an is the number of pairs (ai, aj) that satisfy i < j and ai > aj . Given n and the inversion number m, your task is to find the smallest permutation of the set { 1, 2, . . . , n }, whose inversion number is exactly m. 
A permutation a1, a2, . . . , an is smaller than b1, b2, . . . , bn if and only if there exists an integer k such that aj = bj for 1 <= j < k but ak < bk.

Input

The input consists of several test cases. Each line of the input contains two integers n and m. Both of the integers at the last line of the input is −1, which should not be processed. You may assume that 1 <= n <= 50000 and 0 <= m <= n(n − 1)/2.

Output

For each test case, print a line containing the smallest permutation as described above, separates the numbers by single spaces.

Sample Input

5 9
7 3
-1 -1

Sample Output

4 5 3 2 1
1 2 3 4 7 6 5

Source

 

 

/*
找了好久规律,晕了好多次,改了又写,写了又改,终于找出来了,这个问题主要基于以下考虑:
对于任意一个序列i, i + 1, ..., j其最大的inversion number是全部逆序的情况,即
j, j - 1, ..., i + 1, i,值记为in(i, j) = (j - i + 1) * (j - i) / 2
所以这个问题的解决的步骤如下:
(1)对于输入n, seq, 从后往前考虑找到可以涵盖seq值的i, 即in(i, n) >= seq
(2)由(1)可知,i -> n足够用来表示值为seq的insersion number,所以1-> i - 1只要按照
升序打印即可
(3)剩下的i -> n如何表示值为seq的逆序数呢?考察几个例子不难发现.剩下的i -> n的形式
一定是 k, v1, v2, ..., vn-1,其中k为i->n中的任意一个数, {v1, v2, v3, ..., vn-1}是
除k以外剩下的数的完全逆序形式.例如:加入i = 5, n = 10, {7, 10, 9, 8, 6, 5}就是这样
一种形式.那么剩下的任务就是找出这个k即可.由上述分析我们不难列出方程式:
k - i + (n - i) * (n - i - 1) / 2 = seq, 其中k - i表示大头的k对这个数列逆序的贡献
数, (n - i) * (n - i - 1) / 2表示剩下的除k以外的i->n完全逆序数列的贡献度,这样把k
解出来即可.
*/
 

Windows11 升级到24H2后,原本的protel99se软件的DDB图纸文件打不开解决办法 Windows11更新后无法打开DDB文件 阅读详情

相关推荐

OpenClaw 完整部署教程

版本:OpenClaw 2026.2.13更新日期:2026-02-26适用系统:Linux (Ubuntu/Debian/CentOS)

qq_39436086的博客 2318

【算法实验 Lab-report-unit-1-03】

Let { A1,A2,…,An } be a permutation of the set{ 1,2,…, n}. If i < j and Ai > Aj then the pair (Ai,Aj) is called an “inversion” of the permutation. For example, the permutation {3, 1, 4, 2} has three inversions: (3,1), (3,2) and (4,2). The inversion t

allto的博客 608

飞塔防火墙认证绕过漏洞(CVE-2022-40684)深度剖析与实战复现

本文深度剖析了Fortinet飞塔防火墙高危认证绕过漏洞CVE-2022-40684的原理与影响。该漏洞允许攻击者通过构造包含特定Forwarded头和User-Agent的HTTP请求,无需凭证即可绕过认证,以管理员身份访问设备。文章详细演示了从环境搭建到实战复现,最终植入SSH密钥获取控制权的完整过程,并提供了漏洞挖掘技巧与关键防御建议。

d6e7f8g9h的博客 708

ZOJ_1201_Inversion

Inversion Time Limit: 2 Seconds      Memory Limit: 65536 KB   Let { A1,A2,...,An } be a permutation of the set{ 1,2,..., n}. If i Aj then the pair (Ai,Aj) is called an "inversion" of the permut

博观而约取,厚积而薄发 982

电脑版微信多开,最详细教程没有之一

首先桌面任意的位置右键新建文本文档输入如下代码: TASKKILL /F/IM WECHAT.EXE start " " "D:\Program Files (x86)\Tencent\WeChat\WeChat.exe" start " " "D:\Program Files (x86)\Tencent\WeChat\WeChat.exe" ...

大超子 4390

ThinkAdmin后台Getshell

通过文件包含或者图片马的方式Getshell。修改其可允许的文件类型,php不允许,可添加。系统管理->系统参数配置->本地服务器存储。

hot_milk1的博客 1864

5.1--5.1.1 Inversions 反序(上)

从5.1的标题COMBINATORIAL PROPERTIES OF PERMUTATIONS来看,这一节应该会涉及比较多的组合数学的东西,这一节也属于比较有意思的一节。 反序和反序对 Inversions 反序,这是什么概念呢?对于排序,当然,排列是重要的研究对象,

Em_Num_Cool的专栏 1028

QtNodeEditor实战:构建高效可视化编程环境的完整指南

本文是QtNodeEditor实战的完整指南,详细介绍了如何利用这一基于Qt框架的可视化编程工具构建高效节点编辑器。内容涵盖从快速集成、自定义节点模型到深入理解MVC数据流架构,并提供了样式定制、场景序列化、动态端口等高级功能的实现方法,帮助开发者快速搭建灵活、可维护的可视化编程环境。

lemon的博客 701

POJ 2085 Inversion 数学题

对于任意一个序列i, i + 1, ..., j其最大的inversion number是全部逆序的情况,即j, j - 1, ..., i + 1, i,值记为in(i, j) = (j - i + 1) * (j - i) / 2所以这个问题的解决的步骤如下:(1)对于输入n, seq, 从后往前考虑找到可以涵盖seq值的i, 即in(i, n) >= seq(2)由(1)可知,i -> n足够用来表示值为seq的insersion number,所以1-> i - 1只要按照升序打印即可(3)剩下的i

Coding for Dreams 2349

AlphaPose复现配置教程

AlphaPose是一种准确的多人姿态估计器,这是第一个在COCO数据集上达到70+ mAP (75 mAP)和在MPII数据集上达到80+ mAP (82.1 mAP)的开源系统。为了匹配跨帧的同一人的姿态,我们还提供了一种高效的在线姿态跟踪器,称为Pose Flow。这是第一个在PoseTrack挑战数据集上达到60+ mAP (66.5 mAP)和50+ MOTA (58.3 MOTA)的开源在线姿态跟踪器。AlphaPose支持Linux和Windows操作系统!指路👉。

m0_56661101的博客 4527

Matlab 曲面平滑与点云处理

曲面平滑是一种常见的数学和计算机图形学技术,可以用来消除噪声、填补数据间隙,以及改善曲面的外观。在点云处理中,曲面平滑也被广泛应用于重建、拟合和可视化等领域。本文将介绍如何使用 Matlab 进行曲面平滑和点云处理,并提供相应的源代码。通过以上步骤,我们可以使用 Matlab 进行曲面平滑和点云处理。你可以根据具体需求调整参数和算法,以获得理想的曲面平滑效果。接下来,我们可以使用平滑算法对三角化的网格进行曲面平滑。以上代码将绘制原始点云和重建后的点云,并在图形中显示坐标轴和图例。表示平滑的迭代次数。

QfcaLinux的博客 752

C - Minimum Inversion Number

Description The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj.For a given sequence of numbers a1, a2, ..., an, ...

weixin_34198797的博客 166

pg lib的信息及产生pg lib的三种方法

pg lib相比basic lib会多几方面pg 信息。除了pg arc(pg pin)以外,liberty还提供电压值,以及pmk cell的power_down_function功能相关信息。1.电压值除了常见的primary pg还有secondary pg和衬底。2.pg arc后端需要去做redhawk功耗分析,需要pg liberty提供pg arc,如果没有pg arc就需要手动去写custom lib代替3.pmk cell的power_down_function。

m0_61544122的博客 595

poj 2085 Inversion

题目链接题意是求一个长度为n的逆序对为m的序列即数组,求符合条件的字典序最小的序列。由于长度为n的序列逆序对数最多为n(n - 1)/2,由于要求字典序最小,所以要用尽量少的数字表示尽量多的的逆序对数。例如长度为4,逆序为3,(2,3,4,1),(1,4,3,2)两个序列都符合要求但是,前者用4个数字表示了逆序3,但后者用3个就可以了。所以第一步逆序对m求出最少用多少(假如

x_chaos的专栏 864

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...

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

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

POJ 2085 Inversion G++ 逆序对 贪心 背

由数字1到n组成的序列,逆序对(ai, aj)满足 i aj。求包含m个逆序对的最小数字序列。 

woniupengpeng的专栏 312

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

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

poj 2085 Inversion 已知数个数为n,逆序数为ver,求最小满足条件的排列

<br />InversionTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 2937 Accepted: 1308<br />DescriptionThe inversion number of an integer sequence a1, a2, . . . , an is the number of pairs (ai, aj) that satisfy i < j and ai > aj . Given n and the inv

kongming_acm的专栏 1007

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

poj1007 逆序数

逆序数

aidway的专栏 573

hdu 1394 Minimum Inversion Number

Problem Description The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i aj. For a given sequence of numbers a1, a2, ..., an, if we move th

MasterG 304

Minimum Inversion Number(线段树经典例题:逆序对)

Problem Description The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj. For a given sequence of numbers a1, a2, ..., ...

xizi_ghq的博客 681

【AtCoder】Beginner Contest 380-G.Another Shuffle Window

Atcoder新手组380场g题题解,使用线段树求解。

weixin_55818116的博客 885

Minimum Inversion Number (线段树求逆序对+规律)

The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj. For a given sequence of numbers a1, a2, ..., an, if we move the f...

点点滴滴 257

Inversion II

题目描述 Let { A1,A2,...,An } be a permutation of the set{ 1,2,..., n}. If i < j and Ai > Aj then the pair (Ai,Aj) is called an "inversion" of the permutation. For example, the permutation {3, ...

苏格拉没有底 566
上一篇: POJ 2049 Finding Nemo
下一篇: POJ 2084 Game of Connections
bobten2008
博客等级 码龄18年 153粉丝 157原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值