朱色虫居
Pages
Home
Featured Posts
2006/10/08
10327-Flip Sort
/*
"Flip Sort"
Level:1.5
Date:2006/10/7
技巧:求前面比自己大的數有幾個,加總後便是inversion所需的次數.
*/
#include
main(){
int n=0,i=0,j=0,tmp=0,times=0;
int input[1000]={0};
while(scanf("%d",&n)==1){
for(i=0;i < n;i++) scanf("%d",&input[i]); for(i=0;i < n;i++) for(j=0;j < i;j++) if(input[j] > input[i])
times++;
printf("Minimum exchange operations : %d\n",times);
times=0;
}
}
1 comment:
歐爺
March 5, 2010 at 10:51 AM
你用的演算法時間複雜度是好像是O(n^2)耶..
為啥這樣會比我用BUBBLE SORT還快呀?
感謝回答
Reply
Delete
Replies
Reply
Add comment
Load more...
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
你用的演算法時間複雜度是好像是O(n^2)耶..
ReplyDelete為啥這樣會比我用BUBBLE SORT還快呀?
感謝回答