Title: hdu4932miaomiao's geometry (violent)
N vertices are given, and you are asked to overwrite These vertices. Coverage conditions: use an equi-length line segment, and a line segment overwrites this point. This point must be at the left or right side of the line segment.
Solution: the problem is solved directly by violence at the beginning, but the question is not clearly understood. A line segment can cover two points. If a point is not used as the left Endpoint or the right endpoint, the length of the smallest line segment in the force is used, and the maximum length is used. However, this may cause problems because the length greater than the shortest length cannot guarantee that there is no intersection between the two line segments. Therefore, only the possible length of a line segment can be enumerated. Up to 100. Verify whether the length meets the meaning of the question. When verifying, you must consider it clearly.
Code:
# Include <cstdio> # include <cstring> # include <algorithm> # include <cmath> using namespace STD; const int n = 55; int N; double num [N]; double ans; int chose [N]; // determines whether it can be selected as the left endpoint bool DFS (int K, double Len) {If (k = N) return true; if (! K | (chose [k-1] & num [k]-num [k-1]> = Len) // serves as the right endpoint chose [k] = 1; else if (k = n-1 | num [k + 1]-num [k]> = Len) {// as the left endpoint if (Num [k + 1]-num [k] = Len | num [k + 1]-num [k]> = 2 * Len) chose [k] = 1; else // length greater than Len but less than 2 * lenchose [k] = 0;} elsereturn false; // return DFS (k + 1, len);} int main () {int t; scanf ("% d", & T); While (t --) {scanf ("% d", & N ); for (INT I = 0; I <n; I ++) scanf ("% lf", & num [I]); sort (Num, num + n ); ans = 0; For (INT I = 1; I <n; I ++) {If (ANS <num [I]-num [I-1] & DFS (0, num [I]-num [I-1]) ans = max (ANS, num [I]-num [I-1]); else if (ANS <(Num [I]-num [I-1]) /2 & DFS (0, (Num [I]-num [I-1])/2) ans = max (ANS, (Num [I]-num [I-1])/2);} printf ("%. 3lf \ n ", ANS);} return 0 ;}
Hdu4932miaomiao's geometry (violent)