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 ...
随机推荐
- Winform动态加载TabControl用法
private void BindTabData() { dtIPD = new DataTable(); //drItem = new DataTable(); //获取[项目大类]列表显示于 Ta ...
- Sencha Touch Guide
1.一些命令 创建APP # Make sure the current working directory is the Sencha Touch 2 SDK 例如D:\Program File ...
- 表格td、th强制换行
表格td.th强制换行 <table style="table-layout:fixed" width="100%"> <tr>< ...
- Python学习_列表推导和Lambda表达式
列表推导目的是减少将一个列表转换为另一个列表时所需编写的代码量,其功能也能用列表迭代完成 1.根据要求创建列表threes_and_fives(列表值包括1到15中能够被3或者5正常的数) three ...
- C#中的反射 Assembly.Load() Assembly.LoadFrom()
一些关于C#反射的知识,估计也就最多达到使用API的程度,至于要深入了解,以现在的水平估计很难做到,所以下面此篇文章,以作为一个阶段的总结. 对于反射的总结,我想从以下几个方面展开,首先是反射程序集, ...
- c# datagridview导出到excel【转载】
c# datagridview导出到excel[转载] http://hi.baidu.com/weizier/blog/item/8212caea1123b4d6d439c9fe.html 本作者使 ...
- 一个简单的makefile,一次性编译本文件夹下所有的cpp文件
代码: CXX := g++ CFLAGS := -g TARGET := xxx.exe SRCS := $(wildcard *.cpp) OBJS := $(patsubst %cpp,%o,$ ...
- xcode升级后, 插件失效修复
1. 首先查看 Xcode 的 UUID,在终端执行 defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilit ...
- PHP练习题(二)
程序6.题目: 假设某人有100,000现金,每经过一次路口需要进行一次交费交费规则为当他现金大于50,000时每次需要交%5,如果现金小于等于50,000时每次交5,000.问此人可以经过多少次这个 ...
- 第 12 章 命令模式【Command Pattern】
以下内容出自:<<24种设计模式介绍与6大设计原则>> 今天讲命令模式,这个模式从名字上看就很简单,命令嘛,老大发命令,小兵执行就是了,确实是这个意思,但是更深化了,用模式来描 ...