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

高手指点,到底哪里错了,总是A不了

Posted by 2010310200722 at 2012-03-11 11:12:27 on Problem 1833
#define max 1030
#include <stdio.h>
int  solve(int a[],int n)
{
    int count=0;
    int m,j;
    int i=n-1;
    for(;i>0;i--)
    {
        for(j=i-1;j>=0;j--)
        {
            if(a[i]>a[j])
            {
               count++;
			   int t=a[i];
               for(m=i;m>j;m--)
               {
                  a[m]=a[m-1];
               }
               a[m]=t;
            }
            if(count==1)return 1;
        }
    }
    if(count==0) return 0;
}
int main()
{
    int a[max];
    int m,n,k,i,j,res;
    scanf("%d",&m);
    while(m--)
    {
		
        scanf("%d%d",&n,&k);
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(j=0;j<k;j++)
         {
             res=solve(a,n);
             if(res==0)
            {
                for(i=0;i<n;i++)
                {
                    a[i]=i+1;
                }
            }
         }
         for(i=0;i<n;i++)
         printf("%d ",a[i]);  
         printf("\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