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. ORM和Core

    .net  core中有哪些被抛弃的类 1.DataTable DataRow SqlDataAdapter DataRow DataColumn DataColumn 虽然这些类不是我ORM核心功能 ...

  2. delphi 对TThread扩充TSimpleThread

    对线程的使用,是每个开发者都应该熟练掌握的,也是进阶的重要一环. 可以这样说,没有线程,连界面假死的问题都解决不了,就更别谈并行处理来提高效率了. 本例对线程进行改进,打造一个基础的线程,以后线程应用 ...

  3. Delphi2007下CIS的clHttp使用

    Delphi组件Clever Suite Internet是一款优秀的网络组件,唯一让我感觉不足的是ClHttp竟然使用了断言,当程序遇到问题的时候就会弹出一个对话框,并显示问题是出在了那个单元里.好 ...

  4. poj1504--求两个数的反转数的和的反转数

    题意:给定4321 5678,结果再反转(1234+8756) 一开始以为是poj1503一样,就稀里糊涂的敲代码,实际上有不同 如题:先求1234 + 8765 ------------------ ...

  5. extern外部方法使用C#简单样例

    外部方法使用C#简单样例 1.添加引用using System.Runtime.InteropServices; 2.声明和实现的连接[DllImport("kernel32", ...

  6. poj2762 Going from u to v or from v to u?

    Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13040 ...

  7. XML转化DS等

    public class XmlData    {        /// <summary>        /// 将DataTable对象转换成XML字符串        /// < ...

  8. node.js(五)字符串转换

    1.stringify函数的基本用法 stringify函数的作用就是序列化对象,也就是说将对象类型转换成一个字符串类型(默认的分割符("&")和分配符("=&q ...

  9. FPGA开发(1)

    `timescale ns / ns module system_ctrl ( //globol clock input clk, input rst_n, //synced signal outpu ...

  10. 2016-09-06 J2EE基础知识之不知

    1.中间件.容器.Web服务器 1.1中间件 中间件是提供系统软件和应用软件之间连接的软件,以便于软件各部件之间的沟通.中间件处于操作系统和更高一级应用程序之间. J2EE提出的背景: 1)企业级应用 ...