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 ...
随机推荐
- python语法学习笔记
函数的参数 定义函数的时候,我们把参数的名字和位置确定下来,函数的接口定义就完成了.对于函数的调用者来说,只需要知道如何传递正确的参数,以及函数将返回什么样的值就够了,函数内部的复杂逻辑被封装起来 ...
- wpf convert png to xaml
原文:wpf convert png to xaml 把png图片转化成xaml资源 <ResourceDictionary xmlns="http://schemas.microso ...
- springboot实现热部署,修改代码不用重启服务
1.引入热部署依赖 <!-- 热部署模块 --> <dependency> <groupId>org.springframework.boot</groupI ...
- postgresql拓展if、ifnull、group_concat函数
postgresql版本是8.2.15. 最近陆续有数据分析师从impala.hive转到查询gpdb,gpdb虽然能够支持在查询语句中带多个distinct,但是缺少相应的if.ifnull.gro ...
- centos7;windows下安装和使用spice
感谢朋友支持本博客,欢迎共同探讨交流,因为能力和时间有限,错误之处在所难免,欢迎指正! 假设转载,请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...
- Simditor用法
一不小心接触到Simditor,瞬间被它优美极简的界面所吸引.Simditor是Tower开源的所见即所得的在线富文本编辑器. Simditor的理念是保持简单,避免过度的功能,每个特性都追求极致的用 ...
- HDU 4572 Bottles Arrangement
具体的证明:点击打开链接 我的想法: 要想保证题目所说 构造最小行的和,仅仅能是这样的情况 ..... m-3 m-2 m-1 m | m m-1 m-2 m-3 ...
- vue.2.0-路由
vue2.0 路由: http://router.vuejs.org/zh-cn/index.html 基本使用: 1. 布局 <router-link to="/home" ...
- nyoj--38--布线问题(克鲁斯卡尔)
布线问题 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 南阳理工学院要进行用电线路改造,现在校长要求设计师设计出一种布线方式,该布线方式需要满足以下条件: 1.把所有的 ...
- 22.dll调用技术
1.dll文件: #include <Windows.h> _declspec(dllexport) void message_hello() { MessageBoxA(, ); } _ ...