【UTR #2】题目排列顺序

题目描述

“又要出题了。” 宇宙出题中心主任 —— 吉米多出题斯基,坐在办公桌前策划即将到来的 UOI。

这场比赛有 $n$ 道题,吉米多出题斯基需要决定这些题目的难度,然后再在汪洋大海中寻找符合该难度的题目。

题目的难度可以用一个 $1$ 到 $n$ 的排列 $a_1, \dots, a_n$ 表示,其中 $a_i$ 表示第 $i$ 道题目在这 $n$ 道题目中是第 $a_i$ 简单的题目,即恰有 $a_i - 1$ 道题目比第 $i$ 道题目简单。

经验丰富的吉米多出题斯基早就悟出了一种科学地决定难度顺序的方法。首先,吉米多出题斯基定义了难度递增子序列为序列 $a_{p_1}, a_{p_2}, \dots, a_{p_k}$ ($1 \le p_1 < p_2 < \dots < p_k \le n$) 满足 $a_{p_1} < a_{p_2} < \dots < a_{p_k}$ 。然后,吉米多出题斯基决定了 $n$ 个整数 $f_1, \dots, f_n$,他希望找出一个难度顺序使得对于每个 $1 \le i \le n$ 均满足以 $a_i$ 结尾的难度递增子序列的最长长度恰好为 $f_i$。

但吉米多出题斯基日理万机,于是他找到了你 —— 风璃殇做不出题耶维奇,请你帮助吉米多出题斯基构造一个符合条件的 $a_1, \dots, a_n$ 吧!

输入

第一行一个正整数 $n$。

接下来一行 $n$ 个数,其中第 $i$ 个数表示 $f_i$。($1 \le f_i \le n$)

输出

输出一行 $n$ 个数,表示 $a_1, \dots, a_n$。

题目保证至少存在一组解。如有多组解,输出任意一组均可。

限制与约定

测试点编号 $n$
1$\le 10$
2
3
4$\le 1000$
5
6
7$\le 10^5$
8
9
10

切道水题冷静一下

很明显的有一个构造方法是,当前最大的数,应该放在\(f_i\)最大,若有相同的情况,要放在最前面的位置

直接双关键词排序,然后就能输出了啊?

#include<cstdio>  
#include<iostream>  
#include<algorithm>  
#include<cstdlib>  
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#define LL long long
 
using namespace std;
 
inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
}
 
inline void read(int &x){
  char c=nc();int b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
int wt,ss[19];
inline void print(int x){
	if (x<0) x=-x,putchar('-'); 
	if (!x) putchar(48); else {
	for (wt=0;x;ss[++wt]=x%10,x/=10);
	for (;wt;putchar(ss[wt]+48),wt--);}
}

int n,ans[100010];
struct data
{
	int f,id;
}a[100010];

bool cmp(data x,data y)
{
	if (x.f==y.f) return x.id<y.id;
	else return x.f>y.f;
}

int main()
{
	read(n);
	for (int i=1;i<=n;i++)
		read(a[i].f),a[i].id=i;
	sort(a+1,a+1+n,cmp);
	for (int i=1;i<=n;i++)
		ans[a[i].id]=n-i+1;
	for (int i=1;i<n;i++)
		print(ans[i]),putchar(' ');
	print(ans[n]),putchar('\n');
	return 0;
}
posted @ 2017-04-24 20:07  Xiejiadong  阅读(209)  评论(0编辑  收藏  举报
levels of contents