Pagini recente » Cod sursa (job #2289130) | Cod sursa (job #1714398) | Cod sursa (job #720357) | Cod sursa (job #3191941) | Cod sursa (job #1488008)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define e 0.001
#define sinA 0.86603502540
#define cosA 0.500000000
#define maxN 1502
using namespace std;
int n, i, j, sol;
struct point
{
double x;
double y;
}v[maxN];
int cmp(const point a, const point b)
{
if (abs(a.x - b.x) < e)
return a.y < b.y;
return a.x < b.x;
}
void read()
{
freopen("triang.in", "r", stdin);
scanf("%d", &n);
for (i = 1; i <= n; ++ i)
scanf("%lf %lf", &v[i].x, &v[i].y);
}
int bs(point a)
{
int i = 1, p = 1 << 10;
while (p)
{
if (i + p <= n && v[i + p].x < a.x )
i += p;
p /= 2;
}
if (v[i].x + e < a.x)
++ i;
if (abs(v[i].x - a.x) > e)
return 0;
p = 1 << 10;
while (p)
{
if (i + p <= n && abs(v[i + p].x - v[i].x) < e && (v[i + p].y < a.y || abs(v[i + p].y - a.y) < e))
i += p;
p /= 2;
}
if ((double) abs(v[i].y - a.y) < e)
return 1;
return 0;
}
void solve()
{
point p;
p.x = 0;
p.y = 0;
sort(v + 1, v + n + 1, cmp);
for (i = 1; i <= n; ++ i)
for (j = i + 1; j <= n; ++ j)
{
p.x = (v[i].x + v[j].x) * cosA + (v[i].y - v[j].y) * sinA;
p.y = (v[j].x - v[i].x) * sinA + (v[i].y + v[j].y) * cosA;
sol += bs(p);
p.x = (v[i].x + v[j].x) * cosA + (v[j].y - v[i].y) * sinA;
p.y = (v[i].x - v[j].x) * sinA + (v[i].y + v[j].y) * cosA;
sol += bs(p);
}
}
void write()
{
freopen("triang.out", "w", stdout);
printf("%d\n", sol / 3);
}
int main()
{
read();
solve();
write();
}