Cod sursa(job #989559)

Utilizator thewildnathNathan Wildenberg thewildnath Data 25 august 2013 21:40:34
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.2 kb
#include<stdio.h>
#include<algorithm>
#include<math.h>
#define eps 1.e-6
using namespace std;

typedef struct punct
{
    double x,y;
}punct;
punct v[1002],a,b;
int n,sol;

inline bool cmp(punct a,punct b)
{
    if(a.x<b.x)
        return true;
    if(a.x>b.x)
        return false;
    if(a.y<b.y)
        return true;
    return false;
}

inline int caut(punct x)
{
    int s,d,m;
    s=1;
    d=n;
    while(s<=d)
    {
        m=(s+d)/2;
        if(fabs(v[m].x-x.x)<=eps&&fabs(v[m].y-x.y)<=eps)
            return 1;
        if(cmp(x,v[m]))
            d=m-1;
        else
            s=m+1;
    }
    return 0;
}

int main()
{
    freopen("patrate3.in","r",stdin);
    freopen("patrate3.out","w",stdout);
    int i,j;
    scanf("%d",&n);
    for(i=1;i<=n;++i)
        scanf("%lf%lf",&v[i].x,&v[i].y);
    sort(v+1,v+1+n,cmp);
    for(i=1;i<n;++i)
    {
        for(j=i+1;j<=n;++j)
        {
            a.x=v[i].x+v[i].y-v[j].y;
            a.y=v[i].y+v[j].x-v[i].x;
            b.x=v[i].y+v[j].x-v[j].y;
            b.y=v[j].x+v[j].y-v[i].x;
            if(caut(a)&&caut(b))
                ++sol;
        }
    }
    printf("%d\n",sol);
    return 0;
}