/* Problem F - sunny spots */ #include #include #include #include enum {birch = 0, chestnut = 1, elm = 2, fir = 3, maple = 4, oak = 5}; /* row column */ char orchard[100][100]; int height; int width; void rundataset (int setnum); void readdata(); int main () { int nsets, i; scanf ("%d", &nsets); for (i = 0; i < nsets; i++) { readdata(); rundataset(i + 1); } return 0; } void readdata () { int i, j; char c; scanf ("%d %d", &height, &width); for (i = 0; i < height; i++) { scanf ("%c", &c); // Eat the newline for (j = 0; j < width; j++) { scanf ("%c", &c); orchard[i][j] = c; } } } double leastdistancetotree (int row, int column) { int i, j; double leastdistance = 99999; double dist; int rdist, cdist; for (i = 0; i < height; i++) for (j = 0; j < width; j++) { if (orchard[i][j] == '-') continue; rdist = row - i; cdist = column - j; dist = sqrt(rdist*rdist + cdist*cdist); if (dist < leastdistance) leastdistance = dist; } return leastdistance; } typedef struct { int row, column; } position; position goodplaces[20000]; int gpidx = 0; // next place to write void rundataset (int setnum) { double maxspace = -1, tmp; int i, j; position here; for (i = 0; i < height; i++) for (j = 0; j < width; j++) { tmp = leastdistancetotree (i, j); here.row = i; here.column = j; // reset the goodplaces list if (tmp > maxspace) { gpidx = 1; goodplaces[0] = here; maxspace = tmp; } else if (tmp == maxspace) { goodplaces[gpidx] = here; gpidx ++; } } printf ("Data set %d: The following are all %.2lf yards from the closest tree\n", setnum, maxspace * 10); for (i = 0; i < gpidx; i++) printf ("%d %d\n", goodplaces[i].row + 1, goodplaces[i].column + 1); printf ("\n"); }