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 ...
随机推荐
- Linux学习之十三、快捷键与通配符、数据流重导向
通配符与特殊符号 接下来让我们利用通配符来玩些东西吧!首先,利用通配符配合 ls 找檔名看看: [root@www ~]# LANG=C <==由于与编码有关,先配置语 ...
- instance variables may not be placed in categories
Avoid Properties in Categories Objective-C分类中是不允许增加成员变量的(Instance variables may not be placed in cat ...
- ubuntu系统下设置静态IP
改动 /etc/network/interfaces文件 加入下面内容 # The loopback network interface auto lo eth0 iface lo inet loop ...
- Android开发8:UI组件TextView,EditText,Button
版本:Android4.3 API18 学习整理:liuxinming TextView 概述 TextView直接继承了View(EditText.Button两个UI组件类的父类) TextVie ...
- POJ 1703 Find them, Catch them (数据结构-并查集)
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31102 Accepted: ...
- ASP.NET MVC 学习之路-4
本文在于巩固基础 模型绑定 从URL 获取值 public ActionResult About(int id) { ViewBag.Id = id; return View(); } @{ View ...
- AutoResetEvent和ManualResetEvent
本文在于巩固基础 AutoResetEvent 概念:通知正在等待的线程已发生的事件 如果AutoResetEvent 为非终止状态,则线程会被阻止,并等待当前控制资源的线程通过调用 Set 来通知资 ...
- 在PreparedStatement中设置空值
在PreparedStatement中设置空值 分类: Work& Study java2009-09-10 09:56 922人阅读 评论(0) 收藏 举报 nulltypes数据库 ...
- boost signal2 trackable
挺简单的一个类,只是维护了一个成员 shared_ptr<detail::trackable_pointee> _tracked_ptr; 这样看来的话,所谓的track还是基于智能指针, ...
- Linux学习之traceroute命令
通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径.当然每次数据包由某一同样的出发点(source)到达某一同样的目的地(destination)走的路径可能会不一 ...