Cod sursa(job #1067564)

Utilizator auRSTARHreapca Aurelian auRSTAR Data 27 decembrie 2013 01:17:09
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.58 kb
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define x first
#define y second
using namespace std;
int n,i,j,SOL;
double X,Y,X0,X1,X2,X3,Y0,Y1,Y2,Y3,mijx,mijy,dx,dy;
vector<pair<double,double> >P;
pair<double,double> M,A,B,C,D;
bool cmp(pair<double,double> A,pair<double,double> B)
{
    if(abs(A.x-B.x)<0.00001)return A.y<B.y;
    return A.x<B.x;
}
bool check(pair<double,double> R)
{
    vector<pair<double,double> >::iterator it=lower_bound(P.begin(),P.end(),R,cmp);
    vector<pair<double,double> >::iterator jt=it;
    if(it!=P.begin())jt=it-1;
    if(abs(it->first-R.x)<0.00001 && abs(it->second - R.y)<0.00001)return 1;
    if(abs(jt->first-R.x)<0.00001 && abs(jt->second - R.y)<0.00001)return 1;
    if(it!=P.end()-1)jt=it+1;
    if(abs(jt->first-R.x)<0.00001 && abs(jt->second - R.y)<0.00001)return 1;
    return 0;
}
int main()
{
    freopen("patrate3.in","r",stdin);
    freopen("patrate3.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lf%lf",&X,&Y);
        P.push_back(make_pair(X,Y));
    }
    sort(P.begin(),P.end(),cmp);
    for(vector<pair<double,double> >::iterator it=P.begin();it!=P.end();it++)
        for(vector<pair<double,double> >::iterator jt=it+1;jt!=P.end();jt++)
        {
            B.x=(*it).x+(*it).y-(*jt).y;
            B.y=(*it).y+(*jt).x-(*it).x;
            D.x=(*jt).x+(*it).y-(*jt).y;
            D.y=(*jt).y+(*jt).x-(*it).x;
            if(check(B)&&check(D))
            {
                SOL++;
            }
        }
    printf("%d\n",SOL/2);
    return 0;
}