Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我O(N^2)的算法 100+MS过了,代码仅17行。。。。

Posted by wiseking at 2009-10-27 21:39:50 on Problem 2182 and last updated at 2009-10-27 21:42:13
我O(N^2)的算法 100+MS过了,代码仅17行。。。。

#include <iostream>
  using namespace std;
  int a[8100],f[8100],n;
int main(){
  int i,j,k;
  scanf("%d\n",&n);
  a[1]=1;
  for(i=2;i<=n;i++){
    scanf("%d\n",&k);
    k++;
    for(j=i;j>k;j--)a[j]=a[j-1];
    a[k]=i;
    };
  for(i=1;i<=n;i++)f[a[i]]=i;
  for(i=1;i<=n;i++)cout<<f[i]<<endl;
  return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator