Pagini recente » Cod sursa (job #1580826) | Cod sursa (job #2498723) | Cod sursa (job #2209681) | Cod sursa (job #140736) | Cod sursa (job #978121)
Cod sursa(job #978121)
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
struct point
{
float x;
float y;
};
float dist(float x1,float y1,float x2,float y2)
{
return sqrt(pow((x2-x1),2)+pow((y2-y1),2));
}
int main()
{
freopen("adapost.in","r",stdin);
freopen("adapost.out","w",stdout);
float mat[400][400];
float v[400],max,d_max=0,suma=0;
int aux_x,aux_y[400],nr;
point soldati[400];
point adapost[400];
int n;
cin >> n;
for(int i=0;i<n;i++)
{
cin >> soldati[i].x >> soldati[i].y;
}
for(int i=0;i<n;i++)
{
cin >> adapost[i].x >> adapost[i].y;
for(int j=0;j<n;j++)
{
mat[j][i]=dist(adapost[i].x,adapost[i].y,soldati[j].x,soldati[j].y);
}
}
nr=n;
for(int i=0;i<n;i++)
{
max=0;
for(int j=0;j<nr;j++)
{
v[j]=mat[j][0];
for(int k=1;k<nr;k++)
{
if(v[j]>mat[j][k])
{
v[j]=mat[j][k];
aux_y[j]=k;
}
}
if(v[j]>max)
{
max=v[j];
aux_x=j;
}
}
for(int j=aux_x;j<nr-1;j++)
{
for(int k=0;k<nr;k++)
{
mat[j][k]=mat[j+1][k];
}
}
for(int j=0;j<nr;j++)
{
for(int k=aux_y[aux_x];k<nr-1;k++)
{
mat[j][k]=mat[j][k+1];
}
}
if(d_max<max)
{
d_max=max;
}
suma+=max;
nr--;
}
cout << d_max << " " << suma;
return 0;
}