csu 1555: Inversion Sequence(vector)
来源:互联网 发布:stat是什么软件 编辑:程序博客网 时间:2024/06/11 14:08
1555: Inversion Sequence
Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 360 Solved: 121
[Submit][Status][Web Board]
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
51 2 0 1 030 0 021 1
Sample Output
3 1 5 2 41 2 3No solution
HINT
给你一个序列a[n],要你按照要求去构造一个序列b。
序列a[i]表示序列b中的i前面有a[i]个数比i大。
#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<vector>#define eps 1e-8#define N 10100using namespace std;int n;int a[N];int main() { while(~scanf("%d",&n)) { for(int i=1; i<=n; i++) scanf("%d",&a[i]); vector<int>vec; bool flag=1; for(int i=n; i>=1; i--) { if(a[i]>vec.size()) { flag=0; break; } vec.insert(vec.begin()+a[i],i); } if(!flag)printf("No solution\n"); else { for(int i=0; i<vec.size(); i++) { if(i<vec.size()-1) printf("%d ",vec[i]); else printf("%d\n",vec[i]); } } } return 0;}
- csu 1555: Inversion Sequence(vector)
- CSU 1555 Inversion Sequence
- CSU 1555 Inversion Sequence 给出逆序数求排列 splay
- CSU 1555-Inversion Sequence(逆序数还原,线段树实现)
- csu 1555 Inversion Sequence 线段树反求逆序数
- STL or 线段树 --- CSU 1555: Inversion Sequence
- csu 1060 Nearest Sequence
- CSU 1515 - Sequence (莫队)
- CSU 1515: Sequence
- [ACM] SCU 1555 Inversion Sequence (线段树)
- 线段树 csu1555 Inversion Sequence
- 线段树 csu1555 Inversion Sequence
- CSU 1203 Super-increasing sequence
- CSU - 1203 Super-increasing sequence
- CSU 1203 Super-increasing sequence (模拟)
- CSU 1271: Brackets Sequence(数学啊 )
- CSU 1515 Sequence(莫队算法)
- CSU 1515: Sequence(莫队算法)
- python单元测试(自动化测试)
- 数据结构和算法经典100题-第15题
- 重构反思
- 【设计模式】HeadFirst设计模式(四):工厂模式
- 黑马程序员_Java基础(数据类型,数据类型转换,scanner语句总结)
- csu 1555: Inversion Sequence(vector)
- Java虚拟机工作原理详解
- Linux常用命令(四)
- jsp页面加载js函数
- 项目版本命名规范
- 霍夫变换提取圆心坐标,并拟合直线
- csu 1556: Jerry's trouble(快速幂)
- DWR+SpringMVC整合的3种方式之三
- 正则表达式知识