Cod sursa(job #1926514)

Utilizator rexlcdTenea Mihai rexlcd Data 14 martie 2017 13:43:34
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.36 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>

using namespace std;

pair < double , double > v[1502];

inline bool isEq(double a, double b)
{
    if(abs(a-b)<=0.01)
        return 1;
    return 0;
}

inline double dist(int x, int y)
{
    return sqrt((v[y].first-v[x].first)*(v[y].first-v[x].first)+(v[y].second-v[x].second)*(v[y].second-v[x].second));
}

inline bool cmp(pair < double , double > a, pair < double , double > b)
{
    if(isEq(a.first,b.first))
        return a.second<b.second;
    return a.first<b.first;

}

int main()
{
    ifstream f("triang.in");
    ofstream g("triang.out");
    int n,ans=0;
    f>>n;
    for(int i=1;i<=n;i++)
        f>>v[i].first>>v[i].second;
    sort(v+1,v+n+1,cmp);
    for(int i=1;i<=n-2;i++)
        for(int j=i+1;j<=n-1;j++)
        {
            double l=dist(i,j);
            int st=j+1,dr=n;
            while(st<=dr)
            {
                int m=(st+dr)>>1;
                double l1=dist(i,m), l2=dist(j,m);
                if(isEq(l1,l) && isEq(l2,l))
                {
                    ans++;
                    break;
                }
                else if(l1>l)
                    dr=m-1;
                else
                    st=m+1;
            }
        }
    g<<ans<<'\n';
    f.close();
    g.close();
    return 0;
}