Cod sursa(job #1463014)

Utilizator cojocarugabiReality cojocarugabi Data 19 iulie 2015 17:18:10
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.52 kb
# include <bits/stdc++.h>
# define db long double
# define x first
# define y second
const double pi = 3.14159265359;
const double eps = 1e-3;
using namespace std;
ifstream fi("triang.in");
ofstream fo("triang.out");
pair < db , db > v[1505];
int main(void)
{
    int n;
    fi>>n;
    for (int i = 1;i <= n;++i)
    {
        fi>>v[i].x>>v[i].y;
    }
    sort(v+1,v+1+n);
    int ans = 0;
    db cos60 = cos(M_PI / 3);
    db sin60 = sin(M_PI / 3);
    db cos_60 = cos(-M_PI / 3);
    db sin_60 = sin(-M_PI / 3);
    for (int i = 1;i <= n;++i)
        for (int j = i + 1;j <= n;++j)
        {
            pair < db , db > p,d;
            p.x = v[j].x - v[i].x;
            p.y = v[j].y - v[i].y;
            d.x = p.x * cos60 - p.y * sin60;
            d.y = p.x * sin60 + p.y * cos60;
            d.x += v[i].x;d.y += v[i].y;
            if (d.x < eps) d.x = 0;
            if (d.y < eps) d.y = 0;
            int l = 1;
            for (;l <= n;++l) if (bool(abs(d.x - v[l].x) < eps && abs(d.y - v[l].y) < eps)) break;
            ans += bool(l <= n && abs(d.x - v[l].x) < eps && abs(d.y - v[l].y) < eps);
            d.x = p.x * cos_60 - p.y * sin_60;
            d.y = p.x * sin_60 + p.y * cos_60;
            d.x += v[i].x;d.y += v[i].y;
            l = 1;
            for (;l <= n;++l) if (bool(abs(d.x - v[l].x) < eps && abs(d.y - v[l].y) < eps)) break;
            ans += bool(l <= n && abs(d.x - v[l].x) < eps && abs(d.y - v[l].y) < eps);
        }
    ans /= 3;
    return fo << ans << '\n',0;
}