"Dichotomy + Computational Geometry" Hdu 4033 Regular Polygon

Source: Internet
Author: User
Tags acos

"Dichotomy + Computational Geometry" HDU 4033 Regular polygon Topic Link: hdu 4033 Regular Polygon Topic

The edge length of the polygon is known by the distance from one of the inner points in the regular polygon to all vertices.


Binary problems generally exist with an unknown amount of equation (equation relationship), through the scope of the two unknown amount of search, the geometric relationship of this topic is: Know one side, the internal angle and (around the inner point) equals 360 degrees. According to the triangular inequalities, the two-part boundary is determined, and the sum of the inner angles is 2π.

Talk about the idea.

Based on the last edge of the first Bien Hoa to determine the range of the two-edge, edge determination by the cosine theorem can determine all internal angles, two-point search makes the inner corner of the sum of ==2π, pay attention to the floating-point number error, with the three-state function dcmp sentence.

Reference Code
/*====================================*|* two points + computational geometry *|\*====================================*//*author:hacker_vision*/#include <bits/stdc++.h>#define CLR (k,v) memset (k,v,sizeof (k) )#define EPS 1e-8using namespace  STD;Const int_max =1e3+Ten;Const DoublePI =ACOs(-1);intNDoubleA[_max];intDCMP (Doublex) {///three-state function to avoid accuracy error  if(fabs(x) <eps)return 0;Else returnx<0?-1:1;}DoubleAngleDoublex) {///based on the cosine theorem and the equal regular polygon n edges, return the inner angle and  DoubleAns =0; A[n] = a[0]; for(inti =0; i < n;++ i) ans + =ACOs((a[i]*a[i]+a[i+1]*a[i+1]-X*X)/(2*a[i]*a[i+1]));returnAns;}DoubleBsearch (DoubleLDoubleR) {//Two min to find the edge length  DoubleM while(R-l >= EPS) {m = (L + R)/2.0;//cannot use bit arithmetic Qaq    if(DCMP (Angle (m)-2*PI) = =0)returnM//One side once determined, the internal angle is also determined.    if(Angle (M) <2*PI) L = m + eps;ElseR = m; }return-1;}intMain () {#ifndef Online_judgeFreopen ("Input.txt","R", stdin);#endif //Online_judge   intTCin>>T;intCnt=1; while(t--) {scanf("%d", &n); for(inti =0; i < n; + + i)scanf("%LF", a+i);Doubleres = bsearch (fabs(a[0]-a[n-1]), a[0]+a[n-1]);printf("Case%d:", cnt++);if(DCMP (res+1)==0)puts("Impossible");Else printf("%.3f\n", res); }return 0;}
    • Bold Ctrl + B
    • Italic Body Ctrl + I
    • ReferenceCtrl + Q
    • Insert LinkCtrl + L
    • Inserting codeCtrl + K
    • Insert PictureCtrl + G
    • Promote titleCtrl + H
    • Ordered listCtrl + O
    • Unordered listCtrl + U
    • LineCtrl + R
    • RevokeCtrl + Z
    • RedoCtrl + Y

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Dichotomy + Computational Geometry" Hdu 4033 Regular Polygon

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.