| ||||||||||
| 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 | |||||||||
为什么总是WA呢,请各位大牛不吝赐教!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator