杭电ACM1173

#include<iostream>
#include<iomanip>
using namespace std;
double a[1000000]={0};
double b[1000000]={0};
void swap(double&n1,double&n2)
{
	double temp=n1;
	n1=n2;
	n2=temp;
}
int PartTion(double A[],int m,int n)
{
	double x=A[n];
	int i=m-1;
	for(int j=m;j<n;j++)//
		if(A[j]<=x)
		{
			i++;
			swap(A[i],A[j]);
		}
	swap(A[i+1],A[n]);
	return i+1;
}
void QuickSort(double A[],int m,int n)//快速排序
{
	if(m<n)
	{
		int q=PartTion(A,m,n);
		QuickSort(A,m,q-1);
		QuickSort(A,q+1,n);
	}
}
int main()
{
	int count=0;
	double x=0;
	double y=0;
	cout<<"请输入矿藏的个数: ";
	while(cin>>count)
	{
		for(int i=0;i<count;i++)
		{
			cout<<"输入第"<<i+1<<"组坐标值: ";
			cin>>x>>y;
			a[i]=x;
			b[i]=y;
		}
		QuickSort(a,0,count-1);
		QuickSort(b,0,count-1);
		cout<<"基地的坐标为: ";
		if(count%2!=0)
			cout<<setprecision(2)<<a[count/2]<<' '<<setprecision(2)<<b[count/2];
		if(count%2==0)
			cout<<setprecision(2)<<(a[(count-1)/2]+a[(count-1)/2+1])/2<<' '<<setprecision(2)<<(b[(count-1)/2]+b[(count-1)/2+1])/2;
	}
}

你可能感兴趣的:(杭电ACM1173)