Hdu4932miaomiao's geometry (violent)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.