| ||||||||||
| 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:AC 了 用选择排序就好了啊In Reply To:AC 了 用选择排序就好了啊 Posted by:382784268 at 2009-02-23 23:35:30 唉!差一点就超时了。
891ms
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
int i, j, key, sets, *a, num, step, temp;
scanf("%d", &sets ) ;
while( sets-- ){
scanf("%d", &num ) ;
a = ( int*)malloc( num*sizeof(int) ) ;
for( i = 0; i < num; ++i )
scanf("%d", &a[i] ) ;
step = 0 ;
for( i = 0; i < num; ++i ){
key = i ;
for( j = i+1; j < num; ++j )
if( a[key] > a[j] )
key = j ;
if( key != i ){
temp = a[key] ;
a[key] = a[i] ;
a[i] = temp ;
++ step ;
}
}
free( a ) ;
printf("%d\n", step ) ;
}
return 0 ;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator