Quipex

6355

Mar 7th, 2017
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5. const double eps = 1e-6;
  6. struct pt {double x, y;};
  7. double len(pt a, pt b){
  8.     double a1 = sqrt(a.x*a.x+a.y*a.y);
  9.     double b1 = sqrt(b.x*b.x+b.y*b.y);
  10.     return a1*b1;
  11. }
  12. double scalmltpl(pt a, pt b){
  13.     return a.x*b.x + b.y*a.y;
  14. }
  15. double angle(pt a, pt b){
  16.     return acos(scalmltpl(a,b)/len(a,b));
  17. }
  18. bool d_eq(double a, double b){
  19.     //cout<<a<<";"<<b<<endl;
  20.     return abs(a-b)<eps;
  21. }
  22. int main()
  23. {
  24.     const double pi = 2*asin(1.0);
  25.     int n;
  26.     cin>>n;
  27.     pt* points = new pt[n+1];
  28.     const double ang = pi*(n-2)/n;
  29.  
  30.     int i;
  31.     for (i = 0; i<n; i++)
  32.     {
  33.         cin >> points[i].x >> points[i].y;
  34.     }
  35.     points[n].x = points[0].x;
  36.     points[n].y = points[0].y;
  37.  
  38.     pt line0, line1;
  39.     line0.x = points[1].x - points[0].x;
  40.     line0.y = points[1].y - points[0].y;
  41.     for (i = 1; i < n; i++)
  42.     {
  43.         line1.x = points[i+1].x - points[i].x;
  44.         line1.y = points[i+1].y - points[i].y;
  45.         if(!d_eq(ang, angle(line1, line0)))
  46.         {
  47.             cout<<"NO";
  48.             return 0;
  49.         }
  50.         line0.x = line1.x;
  51.         line0.y = line1.y;
  52.     }
  53.     cout <<"YES";
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment