Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

选择排序超时啊~~~~~~~·

Posted by lovesoccer at 2010-05-23 12:27:09 on Problem 1674
#include <stdio.h>
#include <stdlib.h>
int sort(int a[],int n)
{
    int i,j,k,t,flag;
    flag=0;
    for (i=0;i<n-1;i++)
    {
        k=i;
        for (j=i+1;j<n;j++)
        {
            if (a[j]<a[k])
            {
                k=j;
            }
        }
        if (a[k]!=a[i])
        {
            flag++;
        }
        t=a[k];
        a[k]=a[i];
        a[i]=t;
    }
    return (flag);
}

int main()
{
    int a,i,n;
    int m[10000];
    scanf("%d",&a);
    while (a--)
    {
        scanf("%d",&n);
        for (i=0;i<n;i++)
        {
            scanf("%d",&m[i]);
        }
        printf("%d\n",sort(m,n));
    }
    return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator