Pagini recente » Cod sursa (job #2686045) | Cod sursa (job #209731) | Cod sursa (job #1967738) | Cod sursa (job #1502372) | Cod sursa (job #397348)
Cod sursa(job #397348)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 1000
#define ll long long
#define INF 1000000000
#define double long double
typedef struct { ll x, y; char negativ; double dp; } panta;
typedef struct { ll x, y; } punct;
punct puncte[N + 1];
panta v[N * N + 1];
ll n, contorTrapeze, dimv;
void citeste()
{
scanf("%lld", &n);
int i;
for(i = 0; i < n; ++i) scanf("%lld%lld", &(puncte[i].x), &(puncte[i].y));
}
void calculeazaPante()
{
int i, j, indexPanta = 0;
for(i = 0; i < n; ++i)
{
for(j = i + 1; j < n; ++j)
{
// if(i != j)
// {
// v[indexPanta].x = puncte[i].x - puncte[j].x;
// v[indexPanta].y = puncte[i].y - puncte[j].y;
//
// if(v[indexPanta].x < 0 && v[indexPanta].y < 0)
// {
// v[indexPanta].x = -v[indexPanta].x;
// v[indexPanta].y = -v[indexPanta].y;
// }
//
if(puncte[i].x == puncte[j].x) v[indexPanta].dp = INF;
else v[indexPanta].dp = (double)((double)(puncte[i].y - puncte[j].y) / (double)(puncte[i].x - puncte[j].x));
// if(v[indexPanta].x < 0 || v[indexPanta].y < 0) v[indexPanta].negativ = 1;
// else v[indexPanta].negativ = 0;
indexPanta++;
// }
}
}
dimv = indexPanta;
}
int fcmp(const void* a, const void* b)
{
panta pa, pb;
pa = *((panta*)a);
pb = *((panta*)b);
if(pa.dp < pb.dp) return -1;
else return 1;
// if(pa.negativ && (!pb.negativ)) return -1;
// if((!pa.negativ) && pb.negativ) return 1;
// ll npa = pa.y * pb.x;
// ll npb = pb.y * pa.x;
// if(npa < npb) return -1;
// else return 1;
}
void sorteazaPante()
{
qsort(v, dimv, sizeof(panta), fcmp);
}
void numaraTrapeze()
{
int i;
for(i = 0; i < dimv - 1; ++i)
//if(v[i].x * v[i + 1].y == v[i].y * v[i + 1].x)
if(fabs(v[i].dp - v[i + 1].dp) < 1E-10)
contorTrapeze++;
}
void scrieRezultat()
{
printf("%lld\n", contorTrapeze);
}
int main()
{
freopen("trapez.in", "r", stdin);
freopen("trapez.out", "w", stdout);
citeste();
calculeazaPante();
sorteazaPante();
numaraTrapeze();
scrieRezultat();
return 0;
}