Created
May 10, 2010 10:40
-
-
Save thomasfedb/395913 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#define EPS (double)10e-2 | |
#include <cmath> | |
using namespace std; | |
struct xy { | |
int x, y; | |
}; | |
int numHouses; | |
xy houses[1500]; | |
int main() { | |
scanf("%d", &numHouses); | |
for (int n = 0; n < numHouses; n++) { | |
scanf("%d %d", &houses[n].x, &houses[n].y); | |
} | |
int areas = 0; | |
double runningTot = 0; | |
for (int a = 0; a < numHouses - 2; a++) { | |
for (int b = a + 1; b < numHouses - 1; b++) { | |
for (int c = b + 1; c < numHouses; c++) { | |
// Time for a F**K load of comp geom... | |
double A1 = houses[b].y - houses[a].y; | |
double B1 = houses[a].x - houses[b].x; | |
double A1d = -B1; | |
double B1d = A1; | |
double C1d = A1d * ((houses[a].x + houses[b].x)/2) + B1d * ((houses[a].y + houses[b].y)/2); | |
double A2 = houses[c].y - houses[b].y; | |
double B2 = houses[b].x - houses[c].x; | |
double A2d = -B2; | |
double B2d = A2; | |
double C2d = A2d * ((houses[b].x + houses[c].x)/2) + B2d * ((houses[b].y + houses[c].y)/2); | |
double x = (B2d * C1d - B1d * C2d) / (A1d * B2d - A2d * B1d); | |
double y = (A1d * C2d - A2d * C1d) / (A1d * B2d - A2d * B1d); | |
double r = sqrt((x - houses[a].x) * (x - houses[a].x) + (y - houses[a].y) * (y - houses[a].y)); | |
int covered = 0; | |
for (int n = 0; n < numHouses; n++) { | |
if (r + EPS > sqrt((x - houses[n].x) * (x - houses[n].x) + (y - houses[n].y) * (y - houses[n].y))) { | |
covered++; | |
} | |
} | |
runningTot = (areas * runningTot + covered) / (areas + 1); | |
areas++; | |
} | |
} | |
} | |
printf("%lf", runningTot); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment