Pagini recente » Cod sursa (job #392632) | Cod sursa (job #2672746) | Cod sursa (job #138900) | Cod sursa (job #1937743) | Cod sursa (job #530087)
Cod sursa(job #530087)
// pb067.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include "stdio.h"
#include "math.h"
//#include "stdlib.h"
//#include "time.h"
typedef struct _TPOINT
{
double x;
double y;
} POINT;
void populate()
{
/* FILE *f = fopen("c:\\triang.in", "wt");
srand(time(NULL));
int n = 1500, i = 0;
fprintf(f, "%d\n", n);
for (i = 0; i < n; i++)
{
fprintf(f, "%5lf %5lf\n", (double)(rand()) / rand(), (double)(rand()) / rand());
}
fclose(f);*/
}
int main()
{
//populate();
FILE *f = fopen("triang.in", "rt");
FILE *fres = fopen("triang.out", "wt");
int n = 0, i = 0, j = 0;
fscanf(f, "%d", &n);
POINT p;
POINT lpoints[2001];
double mDist[2001][2001] = { { 0 } };
for (i = 0; i < n; i++)
{
fscanf(f, "%lf%lf", &p.x, &p.y);
lpoints[i].x = p.x;
lpoints[i].y = p.y;
for (j = 0; j < i; j++)
{
double d = sqrt((lpoints[j].x - p.x) * (lpoints[j].x - p.x) + (lpoints[j].y - p.y) * (lpoints[j].y - p.y));
mDist[i][j] = d;
mDist[j][i] = d;
}
}
int k = 0, tr = 0;
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
for (k = j + 1; k < n; k++)
if (mDist[i][j] == mDist[i][k] && mDist[i][j] == mDist[i + k - j][k])
tr++;
}
}
fprintf(fres, "%d", tr);
fclose(fres);
fclose(f);
return 0;
}