Cod sursa(job #2622116)

Utilizator Katherine456719Swan Katherine Katherine456719 Data 31 mai 2020 15:07:44
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <bits/stdc++.h>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;
ifstream f("triang.in");
ofstream g("triang.out");
int n,ans=0;
vector <pair<long double,long 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 and abs(v[r+(1<<p)].second-y) <= 1e-3))))
            r+=(1<<p);
    if(abs(v[r].first - x) <= 1e-3 and 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++)
        {
            long double x,y,difx,dify;
            difx=v[j].first-v[i].first;
            dify=v[j].second-v[i].second;

            x=0.5*(difx-sqrt(3)*dify)+v[i].first;
            y=0.5*(difx*sqrt(3)+dify)+v[i].second;

            if((x!=v[i].first or y!=v[i].second) and (x!=v[j].first or y!=v[j].second))
            cautare(x,y);

            difx=v[i].first-v[j].first;
            dify=v[i].second-v[j].second;

            x=0.5*(difx-sqrt(3)*dify)+v[j].first;
            y=0.5*(difx*sqrt(3)+dify)+v[j].second;
            if((x!=v[i].first or y!=v[i].second) and (x!=v[j].first or y!=v[j].second))
            cautare(x,y);
        }
    g<<ans;
    return 0;
}