Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为啥我首先想到的是冒泡排序。。。。#include <iostream> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <vector> #include <string> int N; int cow[8010]; int cindex[8010]; using namespace std; int main(){ scanf("%d", &N); cow[1]=0; cindex[1]=1; for(int i=2;i<=N;i++){ scanf("%d", cow+i); cindex[i]=i; } for(int i=1;i<=N;i++){ for(int j=1;j<N;j++){ if(cow[j]>=cow[j+1]){ int tmp=cindex[j]; cindex[j]=cindex[j+1]; cindex[j+1]=tmp; tmp=cow[j+1]; cow[j+1]=cow[j]+1; cow[j]=tmp; } } } for(int i=1;i<=N;i++){ cow[cindex[i]]=i; } for(int i=1;i<=N;i++){ cout<<cow[i]<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator