// Chocolate chip cookies (chocolate chip cookies) // PC/Ultraviolet IDs: 111304/10136, popularity: C, success rate: average level: 3 // verdict: accepted // submission date: 2011-11-05 // UV Run Time: 0.020 S // copyright (c) 2011, Qiu. Metaphysis # Yeah dot net // [solution] // if the distance between the two pieces of chocolate is less than or equal to the diameter of the mold, you can move the mold so that the two pieces of chocolate are at the same time on the border of the mold, in this way, it is relatively easy to // determine the number of chocolate chips in the mold. To make the most chocolate chips in the mold, you only need to enumerate all the mold locations such, the maximum value of chocolate slices in the mold is required. # Include <iostream> # include <sstream> # include <cmath> using namespace STD; # define maxn 200 struct point {Double X, Y ;}; point chips [maxn], center, median; int totalchips; // calculates the number of chocolate slices in the mold with a center and a radius of 2.5. Int chipsincutter () {int ncount = 0; For (INT I = 0; I <totalchips; I ++) {double distance = SQRT (POW (CHIPS [I]. x-center. x, 2) + POW (CHIPS [I]. y-center. y, 2); If (distance <= 2.50) ncount ++;} return ncount;} int main (int ac, char * AV []) {istringstream ISS; string line; INT cases; bool printemptyline = false; CIN> cases; cin. ignore (); Getline (CIN, line); While (cases --) {// read the location of the chocolate chip. Totalchips = 0; while (Getline (CIN, line), line. length () {ISS. clear (); ISS. STR (line); ISS> chips [totalchips]. x> chips [totalchips]. y; totalchips ++;} // if the distance between the two points is less than or equal to the diameter of the mold, you can find the center of the mold, so that the two points are on the right of the mold // boundary. Note, if the distance between any two points is greater than 5.0, the maximum number of chocolate slices is 1. Int maxchips = 1; for (INT I = 0; I <totalchips-1; I ++) for (Int J = I + 1; j <totalchips; j ++) {double distance = SQRT (POW (CHIPS [I]. x-Chips [J]. x, 2) + POW (CHIPS [I]. y-Chips [J]. y, 2); If (distance> 5.0) continue; // process special cases first. If (CHIPS [I]. X = chips [J]. x) {center. X = chips [I]. X + SQRT (2.50*2.50-Pow (FABS (CHIPS [I]. y-Chips [J]. y)/2.0, 2); Center. y = (CHIPS [I]. Y + chips [J]. y)/2.0; maxchips = max (maxchips, chipsincutter (); Center. X = chips [I]. x-SQRT (2.50*2.50-Pow (CHIPS [I]. y-Chips [J]. y)/2.0, 2); maxchips = max (maxchips, chipsincutter (); continue;} If (CHIPS [I]. y = chips [J]. y) {center. X = (CHIPS [I]. X + chips [J]. X)/2.0; center. y = chips [I]. Y + SQRT (2.50*2.50-Pow (FABS (CHIPS [I]. x-Chips [J]. x)/2.0, 2); maxchips = max (maxchips, chipsincutter (); Center. y = chips [I]. y-SQRT (2.50*2.50-Pow (FABS (CHIPS [I]. x-Chips [J]. x)/2.0, 2); maxchips = max (maxchips, chipsincutter (); Continue ;}// Based on the straight line and crossing I passing through the center of the center, the close of the vertical line of J // system calculates the coordinates of the center. First, find the midpoint of the vertex I and j connections. Note that two // circles meet the condition (if the distance between two points is 5.0, the two circles overlap ). Point median; median. X = (CHIPS [I]. X + chips [J]. x)/2.0; median. y = (CHIPS [I]. Y + chips [J]. y)/2.0; // calculate the distance from the point to the center of the J link, and then obtain the coordinates of the center. Double slope =-(CHIPS [J]. x-Chips [I]. x)/(CHIPS [J]. y-Chips [I]. y); double segment = SQRT (2.50*2.50-(POW (CHIPS [I]. x-Chips [J]. x, 2) + POW (CHIPS [I]. y-Chips [J]. y, 2)/4.0); Double A = atan (slope); Center. X = median. X + segment * Cos (a); Center. y = median. Y + segment * sin (a); maxchips = max (maxchips, chipsincutter (); Center. X = median. x-segment * Cos (a); Center. y = median. y-segment * sin (a); maxchips = max (maxchips, chipsincutter ();} If (printemptyline) cout <Endl; elseprintemptyline = true; cout <maxchips <Endl;} return 0 ;}