1555: Inversion Sequence

Submit Page    Summary    Time Limit: 2 Sec     Memory Limit: 256 Mb     Submitted: 519     Solved: 195


Description

For sequence i1, i2, i3, … , iN, we set aj to be the number of members in the sequence which are prior to j and greater to j at the same time. The sequence a1, a2, a3, … , aN is referred to as the inversion sequence of the original sequence (i1, i2, i3, … , iN). For example, sequence 1, 2, 0, 1, 0 is the inversion sequence of sequence 3, 1, 5, 2, 4. Your task is to find a full permutation of 1~N that is an original sequence of a given inversion sequence. If there is no permutation meets the conditions please output “No solution”.

Input

There are several test cases.
Each test case contains 1 positive integers N in the first line.(1 ≤ N ≤ 10000).
Followed in the next line is an inversion sequence a1, a2, a3, … , aN (0 ≤ aj < N)
The input will finish with the end of file.

Output

For each case, please output the permutation of 1~N in one line. If there is no permutation meets the conditions, please output “No solution”.

Sample Input

5
1 2 0 1 0
3
0 0 0
2
1 1

Sample Output

3 1 5 2 4
1 2 3
No solution

Hint

Source

题目意思:通过逆序数复原序列
题目意思和样例很难懂
比如样例1:
1 2 0 1 0
1 表示序列中1的前面比1大的数有1个
2 表示序列中2的前面比2大的数有2个
0 表示序列中3的前面比3大的数有0个
1 表示序列中4的前面比4大的数有1个
0 表示序列中5的前面比5大的数有0个
解析一下:
1的前面有1个比1大的,2的前面有2个比2大的,4的前面有一个比4大的
首先,1的位置可以直接确定,因为除了1以外所有的数都比1大,所以1肯定在第二个位置
得到 _ 1 _ _ _
然后考虑2,2的前面有两个数字比2大,因为我们已经确定的数字只有1,1已经比2小了,所以要无视1,其实就是说,2的前面要留下2个空位,这样那2个空位只能放3,4,5,就能保证2的前面一定会有2个数字比它大了,所以
得到 _ 1 _ 2 _
再考虑3,3的前面没有比3大的,1和2都比3小应该直接无视,那么3只能放在第一个位置
得到3 1 _ 2 _
再考虑4,4的前面有一个比它大,所以4的前面应该留一个空格
得到3 1 _ 2 4
最后
得到3 1 5 2 4
具体做法:
采用vector模拟该操作
很神奇!......
 
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define max_v 10005
using namespace std;
int a[max_v];
vector<int> v;
int main()
{
int n;
while(cin>>n)
{
v.clear();
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int flag=;
for(int i=n;i>=;i--)
{
if(v.size()<a[i])
{
flag=;
break;
}
v.insert(v.begin()+a[i],i);
}
if(flag)
{
vector<int>::iterator it;
it=v.begin();
printf("%d",*it);
it++;
for(;it!=v.end();it++)
printf(" %d",*it);
printf("\n");
}else
{
printf("No solution\n");
}
}
return ;
}
/*
题目意思:通过逆序数复原序列
题目意思和样例很难懂
比如样例1:
1 2 0 1 0
1 表示序列中1的前面比1大的数有1个
2 表示序列中2的前面比2大的数有2个
0 表示序列中3的前面比3大的数有0个
1 表示序列中4的前面比4大的数有1个
0 表示序列中5的前面比5大的数有0个 解析一下: 1的前面有1个比1大的,2的前面有2个比2大的,4的前面有一个比4大的 首先,1的位置可以直接确定,因为除了1以外所有的数都比1大,所以1肯定在第二个位置
得到 _ 1 _ _ _
然后考虑2,2的前面有两个数字比2大,因为我们已经确定的数字只有1,1已经比2小了,所以要无视1,其实就是说,2的前面要留下2个空位,这样那2个空位只能放3,4,5,就能保证2的前面一定会有2个数字比它大了,所以
得到 _ 1 _ 2 _
再考虑3,3的前面没有比3大的,1和2都比3小应该直接无视,那么3只能放在第一个位置
得到3 1 _ 2 _
再考虑4,4的前面有一个比它大,所以4的前面应该留一个空格
得到3 1 _ 2 4
最后
得到3 1 5 2 4 具体做法:
采用vector模拟该操作
很神奇!...... */

1555: Inversion Sequence (通过逆序数复原序列 vector的骚操作!!!)的更多相关文章

  1. csu 1555(线段树经典插队模型-根据逆序数还原序列)

    1555: Inversion Sequence Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: 469  Solved: 167[Submit][Sta ...

  2. CSUOJ 1555 Inversion Sequence

    1555: Inversion Sequence Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: 107  Solved: 34 Description ...

  3. hdu1394 Minimum Inversion Number(最小逆序数)

    Minimum Inversion Number Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/O ...

  4. HDU 1394 Minimum Inversion Number(最小逆序数 线段树)

    Minimum Inversion Number [题目链接]Minimum Inversion Number [题目类型]最小逆序数 线段树 &题意: 求一个数列经过n次变换得到的数列其中的 ...

  5. STL or 线段树 --- CSU 1555: Inversion Sequence

    Inversion Sequence Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1555 Mean: 给你一 ...

  6. HDU 1394.Minimum Inversion Number-最小逆序数-完全版线段树(单点增减、区间求和)

    HDU1394.Minimum Inversion Number 这个题求最小逆序数,先建一个空的树,然后每输入一个值,就先查询一下,查询之后,更新线段树,然后遍历一遍,每次将第一个数放到最后之后,减 ...

  7. hdu Minimum Inversion Number(逆序数的小知识与线段树)

    飞! 题解 首先,求逆序数对的思路: 1.得到整个数列后,从前往后扫,统计比a[i]小的,在a[i]后面的有多少个 这样做的话,应该是只有n2的暴力作法,没想到更好的方法 2.统计a[i]前面的,且比 ...

  8. 题解报告:poj 2299 Ultra-QuickSort(BIT求逆序数)

    Description In this problem, you have to analyze a particular sorting algorithm. The algorithm proce ...

  9. NC15163 逆序数

    NC15163 逆序数 题目 题目描述 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数.比如一个序列为 \ ...

随机推荐

  1. 在GDI+中如何实现以左下角为原点的笛卡尔坐标系

    今天写了一个求点集合的凸包的一个算法,虽然结果求解出来了,但是想将过程用GDI+绘制出来,就需要将点绘制出来,然而c#GDI+中绘图的坐标与我们常用数学中笛卡尔坐标系是不一样的,所以就要转换GDI+中 ...

  2. Python之dict和set

    dict Python内置了字典:dict的支持,dict全称dictionary,使用键-值(key-value)存储,具有极快的查找速度 1.例如:查找某位同学对应的成绩,使用“名字”-“成绩”的 ...

  3. CentOS7.4 + Hadoop2.9安装配置管理(分布式)

    1.  规划 1.1.  机器列表 NameNode SecondaryNameNode DataNodes 192.168.1.121 192.168.1.122 192.168.1.101 192 ...

  4. C#+SharpMap的相关代码

    //放大的代码: private void MapZoomIn(NameValueCollection queryString) { SharpMap.Map map = Session[" ...

  5. vue + skyline 搭建 一个开发环境

    1.之前用的是ext +  skyline搭建环境 ,正好最近是做前端的事情,有时间用vue + skyline 搭建一个三维场景 2.准备vue 2.x  ,UI 用的是iview 和element ...

  6. 多表批量导出txt及打压缩包下载

     在一些特殊的业务系统中,有些客户查看报表数据时不需要在浏览器上逐一查看,需要在页面端选择要查看的报表名称(可多选),选择条件,然后将所选中的报表批量导出到txt文件中并且要把批量导出的结果文件打 ...

  7. Redis redis-trib集群配置

    redis文档:http://doc.redisfans.com/ 参考:https://www.cnblogs.com/wuxl360/p/5920330.html http://www.cnblo ...

  8. js 中文长字符截短&关键字符隐藏 自定义过滤器

    两个非常简单的过滤器:隐藏关键字符和字符截短.同样也可以迁移到ng和原生js直接使用(去掉avalon.filters声明即可).后期还有不错的过滤器,还往这里面加 keyword:avalon,js ...

  9. MySQL案例07:MySQL5.7并发复制隐式bug

    我们MySQL线上环境大部分使用的是5.7.18的版本,这个版本已修复了很多bug,但针对主从复制的bug还是有很多的,尤其是一些组复制.并行复制的bug尤为突出,在5.7.19版本有做相应改善和修复 ...

  10. [转] iOS文字排版(CoreText)那些事儿

    文章转载自 http://www.cocoachina.com/applenews/devnews/2014/0521/8504.html iOS文字排版(CoreText)那些事儿 转自阿毛的蛋疼地 ...