Pagini recente » Cod sursa (job #629863) | Cod sursa (job #1036515) | Cod sursa (job #2081496) | Cod sursa (job #2866205) | Cod sursa (job #42362)
Cod sursa(job #42362)
#include <cstdio>
#include <cmath>
int N;
long Sol;
struct Punct
{ double x, y; } A[1501];
void Read();
void Solve();
void Write();
int b_search(Punct, Punct, int, int);
double d(Punct, Punct);
int main()
{
Read();
Solve();
Write();
return 0;
}
void Read()
{
freopen("triang.in", "r", stdin);
scanf("%d", &N);
int i;
for(i=1; i<=N; ++i)
scanf("%lf %lf", &A[i].x, &A[i].y);
fclose(stdin);
}
void Solve()
{
int i, j;
for(i=1; i<N; ++i)
for(j=i+1; j<=N; ++j)
if(A[i].x > A[j].x || (A[i].x == A[j].x && A[i].y > A[j].y))
{
Punct aux;
aux = A[i];
A[i] = A[j];
A[j] = aux;
}
for(i=1; i<=N-2; ++i)
for(j=i+1; j<=N-1; ++j)
{
if(b_search(A[i], A[j], j+1, N))
++ Sol;
}
}
void Write()
{
freopen("triang.out", "w", stdout);
printf("%ld", Sol);
fclose(stdout);
}
double d(Punct A, Punct B)
{
return
sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));
}
int b_search(Punct X, Punct Y, int ls, int ld)
{
int step, i, n = ld - ls + 1;
for(step=1; step<=n; step<<=1);
for(i=ls; step; step>>=1)
if(i+step <= ld && d(X, Y) >= d(X, A[i+step]))
i += step;
double a = d(X, Y);
double b = d(X, A[i]);
double d = b - a, e;
d *= 1000;
int x = (int) d;
e = x;
d = e / 1000;
return !e;
}