hdoj 2404 Permutation Recovery【逆序对】
Permutation Recovery
Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 456 Accepted Submission(s): 316
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?
5
0
1
2
1
2
0
0
9
8
7
6
5
4
3
2
1
0
0
题意:给你一个序列 如2,7,3,5,4,1,8,6 a1=5代表1前边比1大的数的个数为5 (2 7 3 5 4)a4=2代表4前边比4大的数的个数为2个(7 5)现在给你每个数前边比这个数大的数的个数让你求出这个序列
题解:因为所给的数都是按照1~n的顺序给的,所以我们可以看做有n个空格 可以根据这个顺序来向空格中放数,首先,当输入0时代表前边没有比它自己大的数则证明前边的空格都已放满,此时找到数组a的
第一个0的位置就是这个数的位置,如果输入的数k不为0则证明这个数前边还有k个比自己大的数,那么找到第k+1个0的位置,就是这个数的位置
#include<stdio.h>
#include<string.h>
#define MAX 510
int a[MAX];//输入数据
int main()
{
int n,m,j,i,k,t;
while(scanf("%d",&n),n)
{
memset(a,0,sizeof(a));
for(i=1;i<=n;i++)
{
scanf("%d",&k);
int ok=0;
for(j=1;j<=n;j++)
{
bool flag=false;
if(k==0)
{
for(t=1;t<=n;t++)
{
if(a[t]==0)
{
a[t]=i;
flag=true;
break;
}
}
if(flag)
break;
} else
{
if(a[j]==0)
ok++;
if(ok==k+1)
{
a[j]=i;
break;
}
}
}
}
for(i=1;i<n;i++)
printf("%d,",a[i]);
printf("%d",a[n]);
printf("\n");
}
return 0;
}
hdoj 2404 Permutation Recovery【逆序对】的更多相关文章
- CF785CAnton and Permutation(分块 动态逆序对)
Anton likes permutations, especially he likes to permute their elements. Note that a permutation of ...
- HDU 1394Minimum Inversion Number 数状数组 逆序对数量和
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- HDU-1394 Minimum Inversion Number 线段树+逆序对
仍旧在练习线段树中..这道题一开始没有完全理解搞了一上午,感到了自己的shabi.. Minimum Inversion Number Time Limit: 2000/1000 MS (Java/O ...
- Gym 100463A Crossings 逆序对
Crossings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463 Description ...
- HDU 1394 树状数组求逆序对
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- UVA 11990 ``Dynamic'' Inversion 动态逆序对
``Dynamic'' Inversion Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://uva.onlinejudge.org/index ...
- Permutation Recovery(模拟)
Permutation Recovery Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1394 逆序对(nlgn+o(n) )
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- Gym 100463A Crossings (树状数组 逆序对)
Crossings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463 Description ...
随机推荐
- 获取DOM的真实节点
<script type="text/babel"> var Myelement=React.createClass({ handleClick:function(){ ...
- javascript笔记之正则表达式
1.在js正则表达式特殊的需要转义的字符有: ^ $ . * + ? = ! : | \ / ( ) [ ] { } 但实际应用中,还要根据实际情况来判断,以上字符可能不需要转义,也可能不止以上字符 ...
- 【WPF】布局控件总结
<Canvas>:画布,默认不会自动裁减超出内容,即溢出的内容会显示在Canvas外面,这是因为默认 ClipToBounds="False":可设置ClipToBou ...
- CSS3 @keyframes 语法
http://www.w3chtml.com/css3/rules/@keyframes.html <!DOCTYPE html><html lang="zh-cn&quo ...
- js template
http://garann.github.io/template-chooser/ http://www.gbin1.com/technology/javascript/20120917-javasc ...
- [wikioi]数的划分
http://wikioi.com/problem/1039/ 划分型DP.最终的思路是,F[i][j]表示i分成j份,如果分出来的有1,那么去掉1,就是F[i-1][j-1]:如果没有1,那就都减1 ...
- C#子线程更新UI控件的方法总结
http://blog.csdn.net/jqncc/article/details/16342121 在winform C/S程序中经常会在子线程中更新控件的情况,桌面程序UI线程是主线程,当试图从 ...
- 字符串匹配的KMP算法(转)
转载:http://kb.cnblogs.com/page/176818/ 字符串匹配是计算机的基本任务之一. 举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE&quo ...
- 利用if else判断几点是什么时间段
static void Main(string[] args) { while (true) { int a; ...
- 拷贝出你GAC里面的DLL文件
转:http://blog.sina.com.cn/s/blog_573be9bc0100ht65.html 早上和同事探讨如何从GAC中拷贝已经部署的DLL文件的时候,除了以前熟悉的命令行拷贝方法, ...