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. setTimeout OR setInterval?

    setTimeout 和setInterval从字面上应该是可以知道其大意的.timeout:延时:interval:间隔: 两者的区别就像是它们自己的英文解释一样:setTimeout是延时执行,并 ...

  2. onscroll事件没有响应的原因以及vue.js中添加onscroll事件监听的方法

    1 onscroll事件失效 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  3. 安装部署 OpenPAI Install OpenPAI on Ubuntu

      介绍 不管是机器学习的老手,还是入门的新人,都应该装备上尽可能强大的算力.除此之外,还要压榨出硬件的所有潜力来加快模型训练.OpenPAI作为GPU管理的利器,不管是一块GPU,还是上千块GPU, ...

  4. Android开发时,那些相见恨晚的工具或网站!

    本文来我在知乎话题Android开发时你遇到过什么相见恨晚的工具或网站?下的回答! 在实际Android开发过程确实会有很多相见恨晚的工具或网站出现,下面是我自己的一些分享. 1.源码网站 https ...

  5. SSRF学习

    前言 SSRF(Server-Side Request Forgery ,服务器端请求伪造) 是一种由攻击者构造形成由服务器发起请求的一个安全漏洞 SSRF的主要攻击目标为外网无法访问的内部系统. 本 ...

  6. 五种常用web服务器jvm参数设置

     一.tomcat Tomcat默认可以使用的内存为128MB,在较大型的应用项目中,这点内存是不够的,需要调大.有以下几种方法可以选用:第一种方法:在配置文件中设置Windows下,在文件/bi ...

  7. opengl学习笔记

    准备: 1.准备资源:从GLEW1.13.0下载GLEW,并且解压出glew-1.13.0目录.从FreeGLUT官网下载3.0.0版本.直接从这里下的编译后的FreeGLUT,选for MSVC,下 ...

  8. redis介绍(1)命令介绍

    redis 的五大基本类型的简单命令 对key--value中的value的一些简单命令 keys * 查询redis中的所有key exists key 查询key是否存在 flushdb 清空当前 ...

  9. 最常见到的runtime exception 异常

    ArithmeticException, 算术异常ArrayStoreException, 将数组类型不兼容的值赋值给数组元素时抛出的异常BufferOverflowException, 缓冲区溢出异 ...

  10. C语言高精度乘法

    #include <stdio.h> void highPrecision (int N ); ] = {, }, length = ; //开辟一个大的数组,全局变量length记录长度 ...