记录编号 30757 评测结果 AAAAAAAAAA
题目名称 [USACO Jan08] 奶牛的选举 最终得分 100
用户昵称 GravatarTruth.Cirno 是否通过 通过
代码语言 C++ 运行时间 0.089 s
提交时间 2011-10-31 09:07:06 内存使用 0.76 MiB
显示代码纯文本
#include <cstdio>
#include <cstdlib>
using namespace std;

void swap(int &x,int &y)
{
	int temp;
	temp=x;
	x=y;
	y=temp;
}

void qqsort(int* num,int l,int r,int* with1,bool within1,int* with2,bool within2)
{
	int i,j,temp;
	i=l;
	j=r;
	temp=num[rand()%(r-l+1)+l];
	while (i<=j)
	{
		while (num[i]>temp)
			i++;
		while (temp>num[j])
			j--;
		if (i<=j)
		{
			swap(num[i],num[j]);
			if (within1)
				swap(with1[i],with1[j]);
			if (within2)
				swap(with2[i],with2[j]);
			i++;
			j--;
		}
	}
	if (l<j)
		qqsort(num,l,j,with1,within1,with2,within2);
	if (i<r)
		qqsort(num,i,r,with1,within1,with2,within2);
}

int main(void)
{
	freopen("elect.in","r",stdin);
	freopen("elect.out","w",stdout);
	int i,n,k,a[50000],b[50000],c[50000];
	scanf("%d %d\n",&n,&k);
	for (i=0;i<n;i++)
	{
		scanf("%d %d\n",&a[i],&b[i]);
		c[i]=i+1;
	}
	qqsort(a,0,n-1,b,true,c,true);
	qqsort(b,0,k-1,a,false,c,true);
	printf("%d\n",c[0]);
	fclose(stdin);
	fclose(stdout);
	return(0);
}