http://acm.hdu.edu.cn/showproblem.php?pid=1052 尼玛的贪心算法:
#include<stdio.h>
int qsort(int x[],int s,int t)
{
int i,j,mid,tmp;
i=s;
j=t;
mid=x[(i+j)/2];
while (i<=j)
{
while (x[i]>mid) i++;
while (x[j]<mid) j--;
if (i<=j)
{
tmp=x[i];
x[i]=x[j];
x[j]=tmp;
i++;
j--;
}
}
if (s<j) qsort(x,s,j);
if (i<t) qsort(x,i,t);
}
int main()
{
int n,i,i1,i2,j1,j2,ans,a[1003],b[1003];
while (scanf("%d",&n)==1&&n!=0)
{
for (i=1; i<=n; i++)
scanf("%d",&a[i]);
qsort(a,1,n);
for (i=1; i<=n; i++)
scanf("%d",&b[i]);
qsort(b,1,n); //尼玛,这里我复制过来的,qsort(a,1,b);,,wa了我数十次啊!!!!!!
ans=0;
i1=1;
j1=n;
i2=1;
j2=n;
while (i1<=j1)
{
if (a[j1]>b[j2])
{
ans++;
j1--;j2--;
continue;
}
else
if (a[j1]<b[j2])
{
ans--;
j1--;i2++;
continue;
}
if (a[i1]>b[i2])
{
ans++;
i1++;i2++;
continue;
}
else
if (a[i1]<b[i2])
{
ans--;
j1--;i2++;
continue;
}
else
if (a[j1]<b[i2])
{
ans--;
j1--;i2++;
}
else
{
j1--;i2++;
}
}
printf("%d\n",ans*200);
}
return 0;
}