Pagini recente » Cod sursa (job #1202642) | Cod sursa (job #1692117) | Cod sursa (job #2486220) | Cod sursa (job #1333492) | Cod sursa (job #1805926)
//#include <iostream>
#include <fstream>
#include <algorithm>
#include <math.h>
using namespace std;
ifstream ka("trapez.in");
ofstream ki("trapez.out");
const int N_MAX = 1000;
double patrat(double t)
{
return t * t;
}
struct punct
{
long long x, y;
}puncte[N_MAX + 1];
struct dreapta
{
punct p1, p2;
bool operator < (const dreapta arg) const
{
if(p1.x == p2.x)
return false;
else if(arg.p1.x == arg.p2.x)
return true;
else if(fabs((double)(p1.y - p2.y) / (p1.x - p2.x) - (double)(arg.p1.y - arg.p2.y) / (arg.p1.x - arg.p2.x)) < 1e-14)
return sqrt(patrat(p1.y - p2.y) + patrat(p1.x - p2.x)) - sqrt(patrat(arg.p1.y - arg.p2.y) + patrat(arg.p1.x - arg.p2.x)) < 1e-14;
else
return (double)(p1.y - p2.y) / (p1.x - p2.x) - (double)(arg.p1.y - arg.p2.y) / (arg.p1.x - arg.p2.x) < 1e-14;
}
bool operator == (const dreapta arg) const
{
return fabs((p1.y - p2.y) * (arg.p1.x - arg.p2.x) - (arg.p1.y - arg.p2.y) * (p1.x - p2.x)) < 1e-14;
}
}drepte[N_MAX * N_MAX + 1];
int n, marime;
long long sol;
double distanta(int i)
{
return sqrt(patrat(drepte[i].p1.y - drepte[i].p2.y) + patrat(drepte[i].p1.x - drepte[i].p2.x));
}
/*double impartire(int i)
{
if(drepte[i].p1.x == drepte[i].p2.x)
return 1000000000000000000;
else
return (drepte[i].p1.y - drepte[i].p2.y) / (drepte[i].p1.x - drepte[i].p2.x);
}*/
int main()
{
ka >> n;
for(int i = 1; i <= n; i++)
ka >> puncte[i].x >> puncte[i].y;
for(int i = 1; i <= n; i++)
{
for(int j = i + 1; j <= n; j++)
{
dreapta d;
d.p1 = puncte[i];
d.p2 = puncte[j];
drepte[++marime] = d;
}
}
sort(drepte + 1, drepte + marime + 1);
//for(int i = 1; i <= marime; i++)
//cout << drepte[i].p1.x << " " << drepte[i].p1.y << " " << drepte[i].p2.x << " " << drepte[i].p2.y << " " << impartire(i) << '\n';
//cout << '\n';
for(int i = 1; i <= marime; i++)
{
int prev = i + 1;
while(prev <= marime && drepte[prev] == drepte[i])
{
//cout << drepte[i].p1.x << " " << drepte[i].p1.y << " " << drepte[i].p2.x << " " << drepte[i].p2.y << " " << drepte[prev].p1.x << " " << drepte[prev].p1.y << " " << drepte[prev].p2.x << " " << drepte[prev].p2.y << '\n';
if(fabs(distanta(prev) - distanta(i)) < 1e-14)
sol += 2;
else
sol++;
//cout << distanta(prev) << " " << distanta(i) << '\n';
prev++;
}
}
ki << sol;
}