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. AJAX-XMLHttpRequest和本地文件

    网页中可以使用相对URL的能力通常意味着我们能使用本地文件系统来开发和测试HTML,并避免对Web服务器进行不必要的部署. 然而当使用XMLHttpRequest进行Ajax编程时,这通常是不行的. ...

  2. CSS属性之border

    css的border属性相信大家都不陌生了,就是给元素加个边框嘛,在不同的盒模型下,会给元素的宽高带来怎样的影响,相信大家也都很熟悉了,这里就不再赘述,只说说大家平时没有怎么留意的东西. 0.bord ...

  3. eventbus3-intellij-plugin插件搜不到

    一.eventbus3-intellij-plugin插件搜不到

  4. CVE-2017-17215 - 华为HG532命令注入漏洞分析

    前言 前面几天国外有个公司发布了该漏洞的详情.入手的二手 hg532 到货了,分析测试一下. 固件地址:https://ia601506.us.archive.org/22/items/RouterH ...

  5. 安卓脱壳&&协议分析&&burp辅助分析插件编写

    前言 本文由 本人 首发于 先知安全技术社区: https://xianzhi.aliyun.com/forum/user/5274 前言 本文以一个 app 为例,演示对 app脱壳,然后分析其 协 ...

  6. linux系统下安装ssl证书(tomcat)

    1.申请ssl证书 2.下载ssl证书 打开此网址  https://myssl.com/cert_convert.html 将证书文件(xxx.com.crt)和密钥文件上传(xxx.com.key ...

  7. 如何使用 adb 命令实现自动化测试

    如何使用 adb 命令实现自动化测试 一.前提: 1.打开手机调试模式,确保手机已正常连接电脑,可在电脑上通过adb devices命令查看,结果如下说明连接成功: List of devices a ...

  8. frame shiro 概述

    权限管理 权限管理包括用户身份认证和授权两部分,简称认证授权. 身份认证包括用户口令登陆.指纹验证.刷卡等方式. 授权即访问控制,控制谁能访问哪些资源,主体身份认证后分配权限以访问自己可以访问的资源. ...

  9. Django From组件 fields widgets

    一.Form组件之字段 Field required=True, 是否允许为空 widget=None, HTML插件 label=None, 用于生成Label标签或显示内容 initial=Non ...

  10. Vue2学习笔记:class和style

    1.用法 <!DOCTYPE html> <html> <head> <title></title> <meta charset=&q ...