Hdu 5533 positive n edge shape judgment precision processing

Source: Internet
Author: User
Tags acos

Dancing Stars on Me

Time limit:2000/1000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 1098 Accepted Submission (s): 598


problem DescriptionThe sky was brushed, and the stars were cold in a black sky. What a wonderful night. You observed this, sometimes the stars can form a regular polygon in the sky if we connect them properly. You want to the record these moments by your smart camera. Of course, you cannot stay awake all night for capturing. So-decide to-write a program running on the smart camera to check whether the stars can form a regular polygon and cap Ture these moments automatically.

formally, a regular polygon is a convex polygon whose angles was all equal and all its sides has the same length. The area of a regular polygon must is nonzero. We say the stars can form a regular polygon if they is exactly the vertices of some regular polygon. To simplify the problem, we project the sky to a two-dimensional plane here, and you just need to check whether the stars Can form a regular polygon in this plane. 

InputThe first line contains a integerTindicating the total number of test cases. Each test case begins with an integerN, denoting the number of stars in the sky. FollowingNLines, each contains2Integersxi,yi , describe the coordinates ofNStars.

1≤T≤
3≤n≤
−10000≤xi,yi≤10000
All coordinates is distinct.  

Outputfor each test case, please output "' YES '" If the Stars can form a regular polygon. Otherwise, Output "' NO '" (both without quotes). 

Sample Input040, one of the ten 0 

Sample OutputNoyesno 

Source2015ACM/ICPC Asia Changchun Station-Replay (thanks to northeast Normal University) 

recommendHujie | We have carefully selected several similar problems for you: 5830 5829 5828 5827 5826 Test Instructions: give you n points ( -1e4<x,y<=1e4), determine whether the N points can form a positive n-side shape;
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath > #include <vector> #include <queue> #include <map> #include <algorithm> #include <set> #define MM (a) memset (A,0,sizeof (a)) typedef long Long ll;typedef unsigned long long ull;const double EPS = 1e-12;const int    inf = 0x3f3f3f3f;const double Pi=acos ( -1), using namespace std;struct point{int x, y;    void Read () {scanf ("%d%d", &x,&y);    }}p[105],tubao[105];int dcmp (Double A) {if (Fabs (a) <eps) return 0;    else if (a>0) return 1; else return-1;} Point operator-(point A,point B) {return (point) {a.x-b.x,a.y-b.y};} Double dis (point a) {return sqrt (A.X*A.X+A.Y*A.Y);} Double Cross (point A,point b) {return a.x*b.y-b.x*a.y;} Double dot (point A,point b) {return a.x*b.x+a.y*b.y;}    BOOL CMP (point A,point B) {if (a.x!=b.x) return a.x<b.x; else return a.y<b.y;} int Convex_hull (point *p,int n,point *tubao) {sort(P+1,P+N+1,CMP);    int m=0;        for (int i=1;i<=n;i++) {while (M>=2&&cross (p[i]-tubao[m-1],tubao[m]-tubao[m-1]) >0) m--;    Tubao[++m]=p[i];    } int k=m;        for (int i=n-1;i>=1;i--) {while (M-k>=1&&cross (p[i]-tubao[m-1],tubao[m]-tubao[m-1]) >0) m--;    Tubao[++m]=p[i];    } m--; return m;}    int main () {int cas,n;    scanf ("%d", &cas);        while (cas--) {scanf ("%d", &n);        for (int i=1;i<=n;i++) p[i].read ();        int K=convex_hull (P,n,tubao);        TUBAO[K+1]=TUBAO[1];        BOOL Flag=true;        Double tmp= (n-2.0) *pi/n;            for (int. i=1;i<=k-1;i++) {point a=tubao[i+1]-tubao[i],b=tubao[i+2]-tubao[i+1];            Double Cosang=dot (a b)/(DIS (a) *dis (b));            Double Ang=acos (Cosang);            Ang=pi-ang;        if (dcmp (ang-tmp)!=0) {flag=false;break;}        } if (flag) printf ("yes\n");    else printf ("no\n"); } return 0;}

  Analysis: Mainly by the use of this problem to divide down the accuracy of the calculation geometry,

Two ways of processing double type data precision

1. divide to Ong long multiplied , this is definitely right, not wrong.

2.dcmp function , this is relatively simple, but there is a certain precision conditions, if the angle is 1/999999-1/1000000, then subtract is 1e-6*1/999999 to 1e-12 levels, This is possible to use dcmp, such as this problem, because 1-e4<=x<=1e4, then the smallest angle difference is 1/(2*1e4-1) -1/2*1e4 (the smallest angle is 1/2*1e4, the second small angle is 1/(2*1e4-1)) for 1e-8 level >1e-12, so you can use DCMP (eps<1e-12)

 

Hdu 5533 positive n edge shape judgment precision processing

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.