Cod sursa(job #2095127)

Utilizator stefanpiturStefan Alexandru Pitur stefanpitur Data 26 decembrie 2017 23:03:57
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.43 kb
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct pct{
    double x;
    double y;
}point[1001];
bool cmp(pct a, pct b){
    if(a.x>b.x)
        return 0;
    if(a.x==b.x && a.y>b.y)
        return 0;
    return 1;
}
int n;
int susjos(double y, int i){
    while(y>point[i].y)
        i++;
    while(y<point[i].y)
        i--;
    if(y==point[i].y)
        return 1;
    return 0;
}
int cbspeciala(double x, double y){
    int li,ls,mij;
    li=1;
    ls=n;
    while(li<=ls){
        mij=(li+ls)/2;
        if(point[mij].x==x)
            return susjos(y,mij);
        else if(point[mij].x<x)
            li=mij+1;
        else
            ls=mij-1;
    }
    return 0;
}
int main()
{
    freopen("patrate3.in","r",stdin);
    freopen("patrate3.out","w",stdout);
    int i,j,ok,p;
    double xa,ya,xb,yb,xc,yc,xd,yd;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>point[i].x>>point[i].y;
    sort(point+1,point+n+1,cmp);
    p=0;
    for(i=1;i<n;i++)
        for(j=i+1;j<=n;j++){
            xa=point[i].x;
            ya=point[i].y;
            xb=point[j].x;
            yb=point[j].y;
            xc=(xa+xb)/2-(yb-ya)/2;
            yc=(ya+yb)/2+(xb-xa)/2;
            xd=(xa+xb)/2+(yb-ya)/2;
            yd=(ya+yb)/2-(xb-xa)/2;
            ok=cbspeciala(xc,yc);
            if(ok==1){
                ok=cbspeciala(xd,yd);
                if(ok==1)
                    p++;
            }
        }
    cout<<p;
    return 0;
}