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. 基于Maven + SSM (Spring、SpringMVC、Mybatis)构建一个简单的测试项目

    最近在公司实习期间的培训交流中有机会接触到SSM,然后自己花费1周的时间投入学习.谈不上深刻理解其中原理,所以没有涉及理论知识,只是浅层次的学习如何使用,在此将学习过程记录整理出来,一方面自己备用:另 ...

  2. (项目积累的)SQL数据库点滴

    最近的的系统用的数据库是mssql,软件mssql 2008 r2 1.存储过程:后勤的综合管理系统(后端内网访问)三层架构配套用的是存储过程,里面列表展示的都是用存储过程,如下: 1)数据库脚本 U ...

  3. Error no matching function for call to 'std::exception::exception(const char [15])'

    Error no matching function for call to 'std::exception::exception(const char [15])' Error 'logic_err ...

  4. Azure 镜像市场发布商指南

    Azure 镜像市场发布商指南 本指南提供独立软件供应商产品上架到 Azure 镜像市场(以下简称 Azure 镜像市场)需要遵循的全流程. 文档适用范围 本指南适用于希望通过由世纪互联运营的Micr ...

  5. [UI] 精美UI界面欣赏[7]

    精美UI界面欣赏[7] 视频地址: http://v.youku.com/v_show/id_XOTM0MDUzNTg0.html UI介绍地址: http://www.zhihu.com/quest ...

  6. mysql内存评估计算

    这是一个可以评估mysql内存使用大小的网站,根据一些基本的参数,来确定的. 网站:http://www.mysqlcalculator.com/

  7. Redis学习---Redis操作之有序集合

    有序集合,在集合的基础上,为每元素排序:元素的排序需要根据另外一个值来进行比较,所以,对于有序集合,每一个元素有两个值,即:值和分数,分数专门用来做排序. zadd(name, *args, **kw ...

  8. PHP防SQL注入和XSS攻击

    摘要: 就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.在用户名输入框中输入:' or 1=1#,密码随便输入,这时候的合成后的SQL ...

  9. 在 vSphere 5.x/6.0 中配置 Network Dump Collector 服务 (2002954)

    vmware KB: https://kb.vmware.com/s/article/2002954?lang=zh_CN 重点配置命令: 使用 vSphere Client 连接到 vCenter ...

  10. 关于Matlab里面的四个取整(舍入)函数:Floor, Ceil, Fix, Round的解释(转)

    转自http://blog.sina.com.cn/s/blog_48ebd4fb010009c2.html   floor:朝负无穷方向舍入 B = floor(A) rounds the elem ...