ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1768. Circular Strings

Please help me
Posted by Tigran92[RAU_902] 19 Nov 2010 20:07
Who can tell me what is wrong?

// Geometry.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define sz(a)    (a.size())
#define all(a)   (a.begin(),a.end())
#define Sort(a)  (sort(all(a)))
#define pb       (push_back)
#define dump(x)    cerr<<#x<<" = "<<(x)<<endl;
#define debug(x)  cerr<<#x<<" = "<<(x)<<" (L"<< __LINE__ <<")"<<" "<< __FILE__ <<endl;
#define eps 1e-7
int sign (double x)  { return ((x)>eps?1:((x)<-eps?2:0));}


const double PI=acos(-1.0);
const int INF=2100000000;
struct point {
    double x;
    double y;
};
struct line {
    point a;
    point b;
};
double mult(point p1,point p2,point p0){
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double sqrdist(point a,point b){
    return ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int is_convex(int n,point *p){
    int i,s[3]={1,1,1};
    for(i=0;i<n && s[1]|s[2];i++){
        double x=(mult(p[(i+1)%n],p[(i+2)%n],p[i]));
        s[sign(x)]=0;
    }
    return s[1]|s[2];
}
bool dist(int n,point *p){
    double dis=sqrdist(p[0],p[1]);
    int i;
    for(i=0;i<n;i++){
        if(fabs(dis-sqrdist(p[i],p[(i+1)%n]))>=eps){
            return (false);
        }
    }
    return (true);
}
double distance1(point a,point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double getangle(point a,point b,point c){
    double sq=((a.x-b.x)*(a.y-c.y)-(a.x-c.x)*(a.y-b.y));
    double ab=distance1(a,b);
    double bc=distance1(b,c);
    double sinphi=(ab*bc)/sq;
    return asin(sinphi);
}
bool isangles(int n,point *p){
    double sinphi=getangle(p[0],p[1],p[2]);
    int i;
    for(i=0;i<n;i++){
        if(fabs(sinphi-getangle(p[i],p[(i+1)%n],p[(i+2)%n]))>eps){
            return (false);
        }
    }
    return (true);
}
bool isRight(int n,point *p){
    if(dist(n,p) && is_convex(n,p) && isangles(n,p)){
        return (true);
    }
    return (false);
}
int main(){
    int n;
    int i;
    cin>>n;
    point *p=new point [n];
    for(i=0;i<n;i++){
        cin>>p[i].x;
        cin>>p[i].y;
    }
    (isRight(n,p))?(puts("YES")):(puts("NO"));
    return (0);
}