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 |
Re:高手请指点一下In Reply To:高手请指点一下 Posted by:iammk at 2009-03-31 16:18:48 逻辑正确的话,看一下n=1的情况 > #include<iostream> > using namespace std; > void search(int array[],int n) > { > int i,j; > int k,k1,k2; > int temp; > for(k=2;k<n;k++) > if(array[k-1]<array[k]&&k>1) //找到最后的循序数字 > i=k; > if(i>1) > { > j=1; > for(k=i;k<=n;k++) > if(array[i-1]<array[k]&&k>1) > j=k; > temp=array[j]; > array[j]=array[i-1]; > array[i-1]=temp; > for(k1=i,k2=n-1;k1<k2;k1++,k2--) > { > temp=array[k1]; > array[k1]=array[k2]; > array[k2]=temp; > } > } > else > { > for(i=1;i<n;i++) > array[i]=i; //最后一组数组,回到起始位置 > } > } > int main() > { > int n,k,i; > int count; > int *array; > cin>>count; > while(count--) > { > scanf("%d%d",&n,&k); > array=new int[n+1]; > for(i=1;i<=n;i++) > scanf("%d",&array[i]); > while(k>0) > { > search(array,n+1); > k--; > } > for(i=1;i<=n;i++) > printf("%d ",array[i]); > printf("\n"); > } > delete array; > return 0; > }我这个为什么过不了?(wrong answer)请帮帮看看 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator