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

为什么总是WA呢,请各位大牛不吝赐教!

Posted by wlyayjh at 2009-10-12 22:36:24 on Problem 1833
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int nums[1100];

int compare(const void* elem1,const void* elem2)
{
	return (strcmp((char*)elem1,(char*)elem2));
}

int main()
{
	int T,t,n,k,i,j,l;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&k);
		for(i=0;i<n;i++)
			scanf("%d",nums+i);
		for(i=0;i<k;i++)
		{
			for(j=n-1;j>=0;j--)
			{
				if(j==0)
				{
					qsort(nums,n,sizeof(int),compare);
					break;
				}
				if(nums[j-1]<nums[j])
				{
					for(l=(j+n-1)/2;!(nums[l]>nums[j-1]&&(l==n-1||nums[l+1]<nums[j-1]));)
					{
						if(nums[j-1]+1<nums[l])
							l=(l+n)/2;
						else
							l=(l-1+j)/2;
					}
					t=nums[j-1];
					nums[j-1]=nums[l];
					nums[l]=t;
					qsort(nums+j,n-j,sizeof(int),compare);
					break;
				}
			}			
		}
		for(i=0;i<n-1;i++)
			printf("%d ",nums[i]);
		printf("%d\n",nums[n-1]);

	}
	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