HDU 4033 Regular Polygon Computational geometry dichotomy + cosine theorem

Source: Internet
Author: User
Tags acos

Topic links

Give a regular polygon of n vertices, give the distance from a point to n vertices within the polygon, and let you find the edge length of the polygon.

The two sides are long, and then the cosine theorem is used to find the angle between the adjacent two sides, see all the added up is not 2Pi.

#include <iostream>#include<vector>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#include<Set>#include<string>#include<queue>#include<stack>#include<bitset>using namespacestd;#definePB (x) push_back (x)#definell Long Long#defineMK (x, y) make_pair (x, y)#defineLson L, M, rt<<1#defineMem (a) memset (a, 0, sizeof (a))#defineRson m+1, R, rt<<1|1#defineMem1 (a) memset (a,-1, sizeof (a))#defineMEM2 (a) memset (a, 0x3f, sizeof (a))#defineRep (i, N, a) for (int i = A; i<n; i++)#defineFi first#defineSe Secondtypedef pair<int,int>PLL;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-8;Const intMoD = 1e9+7;Const intINF =1061109567;Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} };Doublea[104];intMain () {intT, N; CIN>>T;  for(intCasee =1; casee<=t; casee++) {printf ("Case %d:", Casee); CIN>>N;  for(inti =0; i<n; i++) {scanf ("%LF", &A[i]); }        DoubleL =-inf, r =inf;  for(inti =0; i<n; i++) {L= Max (L, Fabs (a[i]-a[(i+1)%n])); R= Min (r, a[i]+a[(i+1)%n]); }        intFlag =0;  while(Fabs (R-L) >EPS) {            DoubleMid = (l+r)/2, ans =0;  for(inti =0; i<n; i++) {                intTMP = (i+1)%O; Ans+ = ACOs ((a[i]*a[i]+a[tmp]*a[tmp]-mid*mid)/(2*a[i]*a[tmp])); }            if(Fabs (ans-2*PI) <EPS) {Flag=1;  Break; }            if(ans>2*PI) R=mid; ElseL=mid; }        if(flag) {printf ("%.3f\n", L); } Else{puts ("Impossible"); }    }    return 0;}

HDU 4033 Regular Polygon Computational geometry dichotomy + cosine theorem

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.