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. JQuery DataTables Editor---页面内容修改&&数据库信息修改 (1)

    我们使用jquery datatables 不光是为了对数据的展示,同时需要对数据惊行简单的操作,这个操作分为两个部分:1.页面内容的修改:2.对应的数据库信息的修改. 前一篇博文介绍了页面级的操作, ...

  2. MRD-5012型RS232,RS485有源隔离中继模块,采用磁隔离技术,金升阳DC-DC隔离电源,纯硬件自适应方向,速度高达256000bps

    RS485\RS232磁隔离中继模块MRD-5012能够实现232转485或者485转485通信信号的电气隔离,同时提高驱动能力,能够在实现通信信号隔离并且延长通信距离,使485节点可以最大增加到25 ...

  3. Intellij IDEA开发第一个android应用教程

    用惯eclipse的同学们可以试试通过Intellij IDEA来开发一个android应用.下面是具体的教程. 首先:下载Intellij IDEA.最新版本是12.官方提供两个版本.一个是Comm ...

  4. Java实现邮件代理发送

    使用java实现邮件发送 首先需要添加jar文件mailapi.jarstmp.jar 1 import java.util.Properties; import javax.mail.Address ...

  5. Qt部件学习之-烧鹅

    1,布局管理器 candidates

  6. 初识Java--线程同步(2)

    本文讲述Java中的线程同步和生产者消费者问题,其中主要涉及线程同步和wait().notify()方法的用法. wait和notify方法只能用在线程同步中,wait和notify是object的方 ...

  7. MVC中Json的使用:Controller中Json的处理【转】

    一.当查询得到的数据符合前台要求,不需要做任何处理,直接DataList To Json 返回前台. 代码: , out recordCount); return Json(allEntities, ...

  8. Android入门——UI(8)——Fragment(2)

    先演示一下如何在一个activity中放置两个Fragment,先定义两个Fragment <?xml version="1.0" encoding="utf-8& ...

  9. 多线程11_张孝祥 java5的线程锁技术

    本例子因为两个线程公用同线程中,使用同一个对象,实现了他们公用一把锁,实现了同一个方法的互斥. package locks; /** *会被打乱的效果 */ public class LockTest ...

  10. ASP.NET MVC 与Form表单交互

    一,Form包含文件类(单选文件) <form id="ImgForm" method="POST" enctype="multipart/fo ...