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 |
O(N^2)当然不行了,要O(N)或O(NLogN)In Reply To:谁能告诉我,我的程序为什么超时? Posted by:wanpi0user at 2005-04-17 12:12:00 > 我的2085的解答代码 > #include<iostream> > using namespace std; > int main(){ > int arr[50001],n,m,rev,i,j,t; > while(1){ > cin>>n>>m;if(n==-1&&m==-1) break; > for(i=1;i<=n;i++) arr[i]=i; > rev=0; > for(i=n-1;rev<m;i--){ > for(j=n;j>i;j--){ > t=arr[i];arr[i]=arr[j];arr[j]=t; > if(++rev==m) break; > } > } > for(i=1;i<=n;i++) cout<<arr[i]<<" "; > cout<<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