Pagini recente » Cod sursa (job #2068896) | Cod sursa (job #2147089) | Cod sursa (job #302607) | Rating Popa Ioan Laurentiu (IonutLaur) | Cod sursa (job #1564543)
#include <stdio.h>
#include <math.h>
#define MAXN 50000
#define BUFF (1 << 20)
FILE *in;
double l[MAXN], c[MAXN];
int d[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
char s[BUFF];
int pin = BUFF;
inline char getch(){
if(pin == BUFF){
fread(s, BUFF, 1, in);
pin = 0;
}
pin++;
return s[pin - 1];
}
inline double getnr(){
char ch;
double rez = 0;
ch = getch();
while(!(ch >= '0' && ch <= '9'))
ch = getch();
while(ch >= '0' && ch <= '9'){
rez *= 10;
rez += ch - '0';
ch = getch();
}
double p = 1;
if(ch == '.'){
ch = getch();
while(ch >= '0' && ch <= '9'){
p /= 10;
rez += p * (ch - '0');
ch = getch();
}
}
return rez;
}
inline double dist(double x, double y, int n){
int i;
double d = 0;
for(i = 0; i < n; i++){
d += sqrt((x - l[i]) * (x - l[i]) + (y - c[i]) * (y - c[i]));
}
return d;
}
int main(){
in = fopen("adapost2.in", "r");
int i;
double n, x = 0, y = 0, pas;
n = (int) getnr();
for(i = 0; i < n; i++){
l[i] = getnr(); c[i] = getnr();
fscanf(in, "%lf%lf", &l[i], &c[i]);
x += l[i]; y += c[i];
}
x /= n; y /= n;
pas = 0.1;
while(pas > 0.00001){
for(i = 0; i < 4; i++){
while(dist(x + d[i][0] * pas, y + d[i][1] * pas, n) < dist(x, y, n)){
x += d[i][0] * pas;
y += d[i][1] * pas;
}
}
pas /= 2;
}
FILE *out = fopen("adapost2.out", "w");
fprintf(out, "%.4lf %.4lf", x, y);
fclose(out);
return 0;
}