Cod sursa(job #2602632)

Utilizator Katherine456719Swan Katherine Katherine456719 Data 17 aprilie 2020 15:31:12
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.24 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;
ifstream f("triang.in");
ofstream g("triang.out");
int n,ans=0;
struct punct
{
    double x,y;
} a,b,c;
vector <pair<double,double>> v;
void cautare(double x,double y)
{
    int r=0;
    for(int p=28; p>=0; p--)
        if(r+(1<<p)<=n and (v[r+(1<<p)].first<=x or ((abs(v[r+(1<<p)].first - x) <= 1e-3 && abs(v[r+(1<<p)].second-y) <= 1e-3))))
            r+=(1<<p);
    if((abs(v[r].first - x) <= 1e-3 && abs(v[r].second-y) <= 1e-3))
        ans++;
}
int main()
{
    f>>n;
    for(int i=1; i<=n; i++)
    {
        double x,y;
        f>>x>>y;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end());
    for(int i=0; i<v.size()-2; i++)
        for(int j=i+1; j<v.size()-1; j++)
        {
            a.x=v[i].first;
            a.y=v[i].second;
            b.x=v[j].first;
            b.y=v[j].second;
            c.x=a.x+(b.x-a.x)/2-((b.y-a.y)*1.732)/2;
            c.y=a.y+((b.x-a.x)*1.732)/2+(b.y-a.y)/2;
            punct d;
            d.x=a.x+(b.x-a.x)/2+((b.y-a.y)*1.732)/2;
            d.y=a.y-((b.x-a.x)*1.732)/2+(b.y-a.y)/2;
            cautare(c.x,c.y);
            cautare(d.x,d.y);
        }
    g<<ans;
    return 0;
}