算法分析里面的邮局地址选择的问题
源代码在线查看: 邮局选地址.txt
input.txt output.txt
5 10
1 2
2 2
1 3
3 -2
3 3
#include
#include
void main()
{
std::ifstream from("input.txt");
std::ofstream to("output.txt");
int n,k1,k2;
from>>n;
int *a=new int[n];
int *b=new int[n];
int *c=new int[n];
int *d=new int[n];
for(int i=0;i {//
from>>k1>>k2;
a[i]=k1;
b[i]=k2;
c[i]=0;
d[i]=0;
}
int x,y;
x=0;
y=0;
for(i=0;i for(int j=0;j {
if(i==j)continue;
c[i]+=abs(a[i]-a[j]);
d[i]+=abs(b[i]-b[j]);
}
x=c[0];
y=d[0];
for(i=1;i if(x>c[i])x=c[i];
for(i=1;i if(y>d[i])y=d[i];
to
delete []a;
delete []b;
from.close();
to.close();
}