Escape Room

5140: Escape Room

时间限制: 1 Sec   内存限制: 128 MB
提交: 111   解决: 50
[ 提交][ 状态][ 讨论版][命题人: admin]

题目描述

As you know, escape rooms became very popular since they allow you to play the role of a video game hero. One such room has the following quiz. You know that the locker password is a permutation of N numbers. A permutation of length N is a sequence of distinct positive integers, whose values are at most N. You got the following hint regarding the password - the length of the longest increasing subsequence starting at position i equals Ai. Therefore you want to find the password using these values. As there can be several possible permutations you want to find the lexicographically smallest one. Permutation P is lexicographically smaller than permutation Q if there is an index i such that Pi < Qi and Pj = Qj for all j < i. It is guaranteed that there is at least one possible permutation satisfying the above constraints. 
Can you open the door?

输入

The first line of the input contains one integer N (1≤N≤105).
The next line contains N space-separated integer Ai (1≤Ai≤N).
It’s guaranteed that at least one possible permutation exists.

输出

Print in one line the lexicographically smallest permutation that satisfies all the conditions.

样例输入

4
1 2 2 1

样例输出

4 2 1 3

题意:给n个数,输出一个序列,使得以第i个位置为首的最长上升子序列长度为ai。
分析:一通乱搞,对着ai排个序,然后对第i个数赋值为n-i+1,也就是当前第几大的数。然后再按输入顺序排回去就行了。
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define INF 0x3f3f3f3f
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
 
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
struct node
{
    int a,b,c;
}e[100005];
int cmp(node p,node q)
{
    if(p.a!=q.a)
        return p.a<q.a;
    return p.b<q.b;
}
int cmp1(node p,node q)
{
    return p.b<q.b;
}
int main()
{
    int n,i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&e[i].a);
        e[i].b=i;
    }
    sort(e+1,e+1+n,cmp);
    for(i=1;i<=n;i++)
        e[i].c=n-i+1;
 
    sort(e+1,e+1+n,cmp1);
    for(i=1;i<=n-1;i++)
        printf("%d ",e[i].c);
    printf("%d\n",e[i].c);
 
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值