Pagini recente » Cod sursa (job #182365) | Cod sursa (job #1309771) | Cod sursa (job #2404356) | Cod sursa (job #240686) | Cod sursa (job #2602632)
#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;
}