"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
- Reference
Ctrl + Q
- Insert Link
Ctrl + L
- Inserting code
Ctrl + K
- Insert Picture
Ctrl + G
- Promote title
Ctrl + H
- Ordered list
Ctrl + O
- Unordered list
Ctrl + U
- Line
Ctrl + R
- Revoke
Ctrl + Z
- Redo
Ctrl + Y
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Dichotomy + Computational Geometry" Hdu 4033 Regular Polygon