Permutation Recovery

Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 451    Accepted Submission(s): 312

Problem Description
Professor
Permula gave a number of permutations of the n integers 1, 2, ..., n to
her students. For each integer i (1 <= i <= n), she asks the
students to write down the number of integers greater than i that
appears 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?

 
Input
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, ..., an. The input ends with n = 0.
 
Output
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.
 
Sample Input
8
5
0
1
2
1
2
0
0
10
9
8
7
6
5
4
3
2
1
0
0
 
Sample Output
2,7,3,5,4,1,8,6
10,9,8,7,6,5,4,3,2,1
题解:这个题就是给你了逆序数,让你求出原排列;我的思路是从1到N,一次放在数组中,因为i之前的肯定比i小,所以如果a[i]=0逆序数加一;证明a[i]还没放,没放肯定比i大喽;
代码:
 #include<stdio.h>
#include<string.h>
const int MAXN=;
int main(){
int N,x;
int ans[MAXN];
while(~scanf("%d",&N),N){
memset(ans,,sizeof(ans));
for(int i=;i<=N;i++){
scanf("%d",&x);
int tot=;
for(int j=;j<=N;j++){
if(ans[j])continue;
if(tot==x){
ans[j]=i;break;
}
if(!ans[j])tot++;
}
}
for(int i=;i<=N;i++){
if(i-)printf(",");
printf("%d",ans[i]);
}
puts("");
}
return ;
}

Permutation Recovery(模拟)的更多相关文章

  1. hdoj 2404 Permutation Recovery【逆序对】

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

  2. TOJ 2130: Permutation Recovery(思维+vector的使用)

    传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=2130 时间限制(普通/Java): ...

  3. Codeforces 1158C Permutation recovery

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

  4. CF-Div.3-B. Minimize the Permutation【模拟·需要清醒的脑子】

    题目传送门 根据字典序,是个人都会想到依次把目前最小的数尽量往前面移动,直到它不能再往前移动,或者已经到了它的期望位置(就是排列的那个位置 比如$i$就应该在位置$i$)为止. 所以我刚开始是这么写的 ...

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

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

  6. OJ题解记录计划

    容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2 ...

  7. csps-s模拟测试62,63Graph,Permutation,Tree,Game题解

    题面:https://www.cnblogs.com/Juve/articles/11631298.html permutation: 参考:https://www.cnblogs.com/clno1 ...

  8. 5.5 省选模拟赛 B Permutation 构造 贪心

    LINK:Permutation 对于这种构造神题 我自然是要补的.为啥就我没想出来哇. 30分还是很好写的 注意8!实际上很小 不需要爆搜 写bfs记录状态即可.至于判断状态是否出现与否 可以开ma ...

  9. leetcode 31. Next Permutation (下一个排列,模拟,二分查找)

    题目链接 31. Next Permutation 题意 给定一段排列,输出其升序相邻的下一段排列.比如[1,3,2]的下一段排列为[2,1,3]. 注意排列呈环形,即[3,2,1]的下一段排列为[1 ...

随机推荐

  1. Google机器学习教程心得(三) 好的feature

    什么造就好的Feature Google Machine Learning Recipes 3 官方中文博客 http://chinagdg.org/2016/03/machine-learning- ...

  2. python中实现多线程的几种方式

    python实现多线程的方式大概有 1.threading 2._thread #!/usr/bin/python #!coding:utf-8 import threading def action ...

  3. webstrom 常用快捷键

    最近在学习javascript,同时发现了一款非常好用的IDE webstrom 现在记录改IDE的快捷键 1. ctrl + shift + n: 打开工程中的文件,目的是打开当前工程下任意目录的文 ...

  4. 论山寨手机与Android联姻 【9】SmartPhone的硬件结构

    如何区别智能手机(SmartPhone)与功能手机(FeaturePhone)? 有一种观点认为,智能手机本质上是功能手机与便携式电脑(Laptop PC)的结合.功能手机的功能受限于制造厂商的预制, ...

  5. C语言的本质(1)——计算机与二进制

    人类的计数方式通常是"逢十进一",称为十进制(Decimal),大概因为人有十个手指,所以十进制是最自然的计数方式,各民族的文字中都有十个数字,而阿拉伯数字0-9是目前最广泛采用的 ...

  6. 怎样学习使用libiconv库

    怎样学习使用libiconv库 - My Study My Study About My Learn or Study etc. 怎样学习使用libiconv库 By Cnangel on Febru ...

  7. Android:实现仿 美团/淘宝 多级分类菜单效果

    本例要实现的是诸如美团/淘宝/百度糯米 多级分类菜单效果.当分类数量许多时能够考虑採用两级分类.而诸如美团这样的表现方式是一个不错的选择. 首先上效果图:      主要代码: 1. PopupWin ...

  8. Flash,一次Bug的思考

    我绝对不算是F黑,大部分时候,我还是很挺Flash平台的,Flash提供了很好的跨平台特性以及Flash Player11后的GPU加速.Stage3D等等,对于开发者来说,绝对让人欣喜若狂(对我是这 ...

  9. 如何启用Oracle EBS Form监控【Z】

    前言: 有时候,因某些需要,必须知道Oracle的Form被使用的情况,以方面我们做出决策: 例如,如果某个Form被使用的次数非常多,那么,这个Form的相关SQL代码就应该优先处理,以减少服务器负 ...

  10. @Resource注解(转)

    @Resource 注解被用来激活一个命名资源(namedresource)的依赖注入,在JavaEE应用程序中,该注解被典型地转换为绑定于JNDI context中的一个对象.Spring确实支持使 ...