ZJU 2425 Inversion
Inversion
This problem will be judged on ZJU. Original ID: 2425
64-bit integer IO format: %lld      Java class name: Main
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 <= 1/2*n*(n-1).
Output
For each test case, print a line containing the smallest permutation as described above, separates the numbers by single spaces. Don't output any trailing spaces at the end of each line, or you may get an 'Presentation Error'!
Sample Input
5 9
7 3
-1 -1
Sample Output
4 5 3 2 1
1 2 3 4 7 6 5
Source
#include <bits/stdc++.h>
using namespace std;
int n,m;
vector<int>ans;
int main(){
while(scanf("%d %d",&n,&m),~n||~m){
ans.clear();
int p = ;
for(; p*(p - ) < (m<<); p++);
for(int i = ; i <= n - p; ++i) ans.push_back(i);
int tmp = n - p + (m - ((p-)*(p-)>>)) + ;
ans.push_back(tmp);
for(int i = n; i > n - p; --i)
if(i != tmp) ans.push_back(i);
for(int i = ; i < ans.size(); ++i)
printf("%d%c",ans[i],i + == ans.size()?'\n':' ');
}
return ;
}
ZJU 2425 Inversion的更多相关文章
- HDU 1394 Minimum Inversion Number   (  树状数组求逆序数    )
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number ...
 - 控制反转Inversion of Control (IoC)  与  依赖注入Dependency Injection (DI)
		
控制反转和依赖注入 控制反转和依赖注入是两个密不可分的方法用来分离你应用程序中的依赖性.控制反转Inversion of Control (IoC) 意味着一个对象不会新创建一个对象并依赖着它来完成工 ...
 - HDU 1394 Minimum Inversion Number(最小逆序数 线段树)
		
Minimum Inversion Number [题目链接]Minimum Inversion Number [题目类型]最小逆序数 线段树 &题意: 求一个数列经过n次变换得到的数列其中的 ...
 - 依赖倒置原则(Dependency Inversion Principle)
		
很多软件工程师都多少在处理 "Bad Design"时有一些痛苦的经历.如果发现这些 "Bad Design" 的始作俑者就是我们自己时,那感觉就更糟糕了.那么 ...
 - HDU 1394 Minimum Inversion Number(最小逆序数/暴力  线段树  树状数组  归并排序)
		
题目链接: 传送门 Minimum Inversion Number Time Limit: 1000MS Memory Limit: 32768 K Description The inve ...
 - Raspberry Pi 3 FAQ --- connect automatically to 'mirrors.zju.edu.cn' when downloading and how to accelerate download
		
modify the software source: The software source is a place where several free application for linux ...
 - Inversion Sequence(csu 1555)
		
Description For sequence i1, i2, i3, … , iN, we set aj to be the number of members in the sequence w ...
 - ACM: 强化训练-Inversion Sequence-线段树 or STL·vector
		
Inversion Sequence Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%lld & %llu D ...
 - ACM Minimum Inversion Number 解题报告 -线段树
		
C - Minimum Inversion Number Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
 
随机推荐
- mysql更改密码与远程管理
			
set password = ': #在当前用户下更改密码 grant all privileges on *.* to root@"%" identified by " ...
 - Could not create connection to database server. Attempted reconnect 3 times. Giving up.错误
			
项目是基于springboot框架,昨天从git上pull代码之后也没有具体看更改的地方,结果运行的时候就报错了. java.sql.SQLNonTransientConnectionExceptio ...
 - 【问题:SSH】win10使用SSH链接服务器时,提示:Host key verification failed
			
异常原因:当前连接新建的验证信息与之前保存的验证信息不一致,将原来的验证信息删除就可以了. 1 使用以下命令,清空之前缓存的信息.或者直接打开C:\Users\Nolan\.ssh\known_hos ...
 - CSU 1506 Double Shortest Paths
			
1506: Double Shortest Paths Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 49 Solved: 5 Description ...
 - 11 hbase源码系列(十一)Put、Delete在服务端是如何处理
			
hbase源码系列(十一)Put.Delete在服务端是如何处理? 在讲完之后HFile和HLog之后,今天我想分享是Put在Region Server经历些了什么?相信前面看了<HTab ...
 - bug14052601
			
AppDelegate.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall cocos2d::ui::Margin::Margin(void ...
 - [Recompose] Merge RxJS Button Event Streams to Build a React Counter Component
			
Combining input streams then using scan to track the results is a common scenario when coding with s ...
 - Android设置背景图片平铺
			
以LinearLayout为例,它提供的background属性将会将背景图片拉伸,相当难看.其实我们仅仅需做少量的改动就能够实现web编程中css背景图片的效果.来试试吧. 创建反复的背景图片 在d ...
 - 【VBA研究】用VBA取得EXCEL随意列有效行数
			
作者:iamlaosong 用VBA对Excel文件进行处理的时候,keyword段的列号编程时往往是不知道的.须要通过參数设定才干知道,因此.我们编程的时候,就不能用这种语句取有效行数: linen ...
 - 关于post请求“CAUTION: Provisional headers are shown”【转】
			
在POST请求中偶尔会出现"CAUTION: Provisional headers are shown" 这个警告的意思是说:请求的资源可能会被(扩展/或其它什么机制)屏蔽掉. ...