Permutation Recovery(模拟)
Permutation Recovery
Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 451 Accepted Submission(s): 312
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 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.
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.
5
0
1
2
1
2
0
0
10
9
8
7
6
5
4
3
2
1
0
0
10,9,8,7,6,5,4,3,2,1
#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(模拟)的更多相关文章
- hdoj 2404 Permutation Recovery【逆序对】
Permutation Recovery Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- TOJ 2130: Permutation Recovery(思维+vector的使用)
传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=2130 时间限制(普通/Java): ...
- Codeforces 1158C Permutation recovery
https://codeforces.com/contest/1158/problem/C 题目 已知 $p_1, p_2, \dots, p_n$ 是 $1$ 到 $n$ 的一个排列. 给出关于这个 ...
- CF-Div.3-B. Minimize the Permutation【模拟·需要清醒的脑子】
题目传送门 根据字典序,是个人都会想到依次把目前最小的数尽量往前面移动,直到它不能再往前移动,或者已经到了它的期望位置(就是排列的那个位置 比如$i$就应该在位置$i$)为止. 所以我刚开始是这么写的 ...
- Codeforces 1159E Permutation recovery(构造+拓扑)
这道题其实只要解决了什么时候输出 -1 ,那么此题的构造方法也就解决了.首先我们可以观察这组 3 3 4 和 3 4 4 ,可以算出第二组是不成立的,在观察一组 2 3 4 5 和 3 2 4 5 ...
- OJ题解记录计划
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001 A+B Problem First AC: 2 ...
- csps-s模拟测试62,63Graph,Permutation,Tree,Game题解
题面:https://www.cnblogs.com/Juve/articles/11631298.html permutation: 参考:https://www.cnblogs.com/clno1 ...
- 5.5 省选模拟赛 B Permutation 构造 贪心
LINK:Permutation 对于这种构造神题 我自然是要补的.为啥就我没想出来哇. 30分还是很好写的 注意8!实际上很小 不需要爆搜 写bfs记录状态即可.至于判断状态是否出现与否 可以开ma ...
- leetcode 31. Next Permutation (下一个排列,模拟,二分查找)
题目链接 31. Next Permutation 题意 给定一段排列,输出其升序相邻的下一段排列.比如[1,3,2]的下一段排列为[2,1,3]. 注意排列呈环形,即[3,2,1]的下一段排列为[1 ...
随机推荐
- 进程序名得到进程ID和句柄与进程的公司名(使用快照和GetPeFileCompany和VerQueryValueW等函数)
WORD GetProcessIdByName(WCHAR *processName){ DWORD processId = 0;HANDLE hProcessSnap=CreateToolhelp ...
- delphi 文件搜索,遍历所有子目录
function ListFiles(path: string): TStringList; var SearchRec: TSearchRec; found: integer; begin resu ...
- vs2008 + OpenCV-2.1.0-win32-vs2008安装
vs2008 + OpenCV-2.1.0-win32-vs2008安装 1. 安装vs2008+sp12. 安装opencv-2.1.0-win32-vs2008,假设安装目录为c:/opencv2 ...
- iterm快捷键及操作技巧(附Linux快捷键)
标签操作 新建标签:command + t 关闭标签:command + w 切换标签:command + 数字 command + 左右方向键 切换全屏:command + enter 查找:com ...
- Genealogical tree(拓扑结构+邻接表+优先队列)
Genealogical tree Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) ...
- java中文乱码解决之道(四)—–java编码转换过程
原文出处:http://cmsblogs.com/?p=1475 前面三篇博客侧重介绍字符.编码问题,通过这三篇博客各位博友对各种字符编码有了一个初步的了解,要了解java的中文问题这是必须要了解的. ...
- Visual Studio使用技巧
编程部分: 1.TODO:书签 打开之后返回上次工作的位置.让我们不再用脑子去记忆,去回顾刚刚工作到的部分. 操作非常easy.例如以下代码所看到的: public DataTable SelectB ...
- 在sql数据库变量中保存单引号的办法
set @strWhere=' AccountName like '+'''%'+@Condition+'%''' 先用'+''''+要在单引号里的内容+''''. 就这样就行了. 主要就是用三个单引 ...
- Quartz 2D官方文档翻译(持续更新中)
转换 核心绘图模型定义了两个完全独立的坐标空间:用户空间,一个是代表文档页,和设备空间,另外一个代表本机设备的分辨率.用户空间坐标是与设备空间中像素分辨率无关的浮点数字.当你想要打印或者显示你的文档 ...
- 20151225--easyUI
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...