Pagini recente » Cod sursa (job #3169477) | Cod sursa (job #1819382) | Cod sursa (job #1327039) | Cod sursa (job #2309408) | Cod sursa (job #3266233)
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
const int NMAX = 1501;
ifstream fin("triang.in");
ofstream fout("triang.out");
struct pct
{
double x, y;
} p[NMAX];
int n;
long long sol;
bool cmp(const pct& a, const pct& b)
{
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
void rotunjire(pct& a)
{
a.x = (int)(a.x * 1000.0) / 1000.0;
a.y = (int)(a.y * 1000.0) / 1000.0;
}
bool cb(const pct& a)
{
int st = 1, dr = n, mij;
while (st <= dr)
{
int mij = (st + dr) / 2;
if(p[mij].x == a.x)
if(p[mij].y == a.y)
return 1;
else if(p[mij].y < a.y)
st = mij + 1;
else
dr = mij - 1;
else if(p[mij].x < a.x)
st = mij + 1;
else
dr = mij - 1;
}
return 0;
}
int main()
{
fin >> n;
for(int i = 1; i <= n; ++i)
{
fin >> p[i].x >> p[i].y;
rotunjire(p[i]);
}
sort (p + 1, p + n + 1, cmp);
for(int i = 1; i < n; ++i)
for(int j = i + 1; j <= n; ++j)
{
pct mij = {(p[i].x + p[j].x) / 2, (p[i].y + p[j].y) / 2}, crt;
crt.x = mij.x - sqrt(3) * (p[i].y - mij.y), crt.y = mij.x + sqrt(3) * (p[i].x - mij.x);
rotunjire(crt);
if(cb(crt)) ++sol;
crt.x = mij.x + sqrt(3) * (p[i].y - mij.y), crt.y = mij.x - sqrt(3) * (p[i].x - mij.x);
rotunjire(crt);
if(cb(crt)) ++sol;
}
fout << sol / 3;
return 0;
}