传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=2130

时间限制(普通/Java):2000MS/20000MS     内存限制:65536KByte

描述

Professor Permula gave a number of permutations of the n integers 1, 2, ... , n to her students. For each integer i, (1 ≤ in), she asks the students to write down the number of integers greater than i that appear before i in the given permutation. This number is denoted ai. For example, if n = 8 and the permutation is 2, 7, 3, 5, 4, 1, 8, 6, then a1 = 5 because there are 5 numbers (2, 7, 3, 5, 4) greater than 1 appearing before it. Similarly, a4 = 2 because there are 2 numbers (7, 5) greater than 4 appearing before it.

John, one of the students in the class, is studying for the final exams now. He found out that he has lost the assignment questions. He only has the answers (the ai's) but not the original permutation. Can you help him determine the original permutation, so he can review how to obtain the answers?

输入

The input consists of a number of test cases. Each test case starts with a line containing the integer n (n ≤ 500). The next n lines give the values of a1, a2, ... , an. The input ends with n = 0.

输出

For each test case, print a line specifying the original permutation. Adjacent elements of a permutation should be separated by a comma. Note that some cases may require you to print lines containing more than 80 characters.

样例输入

8
5
0
1
2
1
2
0
0
10
9
8
7
6
5
4
3
2
1
0
0

样例输出

2,7,3,5,4,1,8,6
10,9,8,7,6,5,4,3,2,1

 

题意:就是给你每个数的逆序数,让你求这个序列。比如说对于序列:2,7,3,5,4,1,8,6 。在出现1之前,有5个比1大的数:2,7,3,5,4。所以a[1] = 5,又比如 6,在6之前有2个比它大的,即:7,8。所以a[6] = 2

      题目就是给了a[1]到a[n],分别代表1---n的逆序数,要求求出这个序列

思路:从后往前来。拿题目中的样例1来解释:序列:2,7,3,5,4,1,8,6

    a[8] 只能等于0  因为 8 是最大的那个数

    a[7] 只能等于0或者 1,因为7是第二大的,a[7]等于0说明7在8的左边,等于1说明7在8的右边

    a[6] 只能等于0或者1或者2,像题目中的,等于2的话,说明6在 {7,8} 这个序列的右边

   以此类推即可把整个序列求出来

注意输出0结束,以及分割用逗号

代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#define LL long long
using namespace std;
int a[],n;
void solve(){
for(int i = ; i < n ; i ++){
scanf("%d",&a[i]);
}
vector<int>v;
v.push_back(n);
for(int i = n-;i >= ; i--){
v.insert(v.begin()+a[i-],i);
}
for(int j = ; j < v.size() ; j++){
j == ? printf("%d",v[j]):printf(",%d",v[j]);
}
puts("");
}
int main()
{
while(scanf("%d",&n),n){
solve();
}
return ;
}

TOJ 2130: Permutation Recovery(思维+vector的使用)的更多相关文章

  1. hdoj 2404 Permutation Recovery【逆序对】

    Permutation Recovery Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. Permutation Recovery(模拟)

    Permutation Recovery Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. Permutation(构造+思维)

    A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of ndistinct positi ...

  4. D. Make a Permutation!(思维)

    D. Make a Permutation! time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  5. 网络寻路(思维+vector的应用)-----------蓝桥备战系列

    标题:网络寻路 X 国的一个网络使用若干条线路连接若干个节点.节点间的通信是双向的.某重要数据包,为了安全起见,必须恰好被转发两次到达目的地.该包可能在任意一个节点产生,我们需要知道该网络中一共有多少 ...

  6. Codeforces 1159E Permutation recovery(构造+拓扑)

    这道题其实只要解决了什么时候输出 -1 ,那么此题的构造方法也就解决了.首先我们可以观察这组 3 3 4 和 3 4 4 ,可以算出第二组是不成立的,在观察一组 2 3 4 5 和  3 2 4 5 ...

  7. Codeforces 1158C Permutation recovery

    https://codeforces.com/contest/1158/problem/C 题目 已知 $p_1, p_2, \dots, p_n$ 是 $1$ 到 $n$ 的一个排列. 给出关于这个 ...

  8. [Locked] Palindrome Permutation I & II

    Palindrome Permutation I Given a string, determine if a permutation of the string could form a palin ...

  9. 【LeetCode】60. Permutation Sequence

    题目: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of t ...

随机推荐

  1. kubernetes添加删除重启节点

    1.添加节点 (master)查看目前节点 [root@k8s-master ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-maste ...

  2. 【ASP.NET 插件】分享一个可视化HTML编辑器 CKEditor.NET

    因为公司网站的可视化HTML编辑器IE兼容性问题,js报错不能使用,于是在网上找到了个还行的,图片本地上传的话直接把图片拖到编辑窗口就可以了.这个编辑器是在开源中国看到的,个人觉得还不错! CKEdi ...

  3. react-native android app名字 app包名、图标和启动图片设置

    1.设置名字 打开 android/app/src/main/res/values/strings.xml 如图,进行修改即可 2.设置图标,最简单可以直接替换,其他后在看 在上图中几个文件夹中都有一 ...

  4. 机器学习进阶-案例实战-图像全景拼接-图像全景拼接(RANSCA) 1.sift.detectAndComputer(获得sift图像关键点) 2.cv2.findHomography(计算单应性矩阵H) 3.cv2.warpPerspective(获得单应性变化后的图像) 4.cv2.line(对关键点位置进行连线画图)

    1. sift.detectAndComputer(gray, None)  # 计算出图像的关键点和sift特征向量 参数说明:gray表示输入的图片 2.cv2.findHomography(kp ...

  5. 正则表达式——WPF输入控件TextBox 限定输入特定字符

    概念: 正则表达式是对字符串操作的一种逻辑公式, 就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符串”, 这个“规则字符串”用来表达对字符串的一种过滤逻辑. 目的: 给定一个正 ...

  6. linux系统基础入门

    使用工具:源码管理,自动部署,web服务器(linux) linux系统基础入门 1.下载地址 2.本文介绍的是一个基于Ubuntu的开源操作系统 下载优麒麟 Ubuntu是一个广泛应用于个人电脑,云 ...

  7. sql server 2008 数据库可疑的解决步骤

    备份并新建同名数据库,并替换原数据文件 1 把问题数据库备份后直接删除 停掉SQLSERVER服务,把服务器上出问题的数据库, 假设名称为 test的数据库文件及日志文件备份到其他目录,然后直接将其删 ...

  8. [linux]如何更新Ubuntu的数据源

    为何要更新数据源?国外的数据源,除了速度慢这个次要因素,更可怕的是有些链接根本不通,导致用户既没有下载东西,也没有看到实质性提示:潜在的危险就是编译错误不能定位,严重时甚至重装系统.本文介绍几个国内有 ...

  9. English: How to Pronounce R [ɹ] Consonant

    English: How to Pronounce R [ɹ] Consonant Share Tweet Share Tagged With: Most Popular, Sound How-To ...

  10. JAVAWEB 一一 Hibernate(框架)

    实体类关联数据库字段,操作实体类,HQL语句对数据结构CRUD) 引入jar包 配置文件 hibernate.cfg.xml User.hbm.xml <?xml version="1 ...