Pagini recente » Cod sursa (job #1586893) | Cod sursa (job #941160) | Cod sursa (job #2747162) | Cod sursa (job #652983) | Cod sursa (job #2072659)
#include <bits/stdc++.h>
using namespace std;
ifstream in("trapez.in");
ofstream out("trapez.out");
int const INF=2e9;
struct point{
int x, y;
}puncte[1001];
struct dreapta{
double panta, c;
}drepte[500001];
bool cmp(dreapta a, dreapta b){
if (a.panta<b.panta) return true;
else if (a.panta==b.panta)
if (a.c<b.c) return true;
return false;
}
int main(){
int i, n, l=0, j, sti, dscz, li, trapeze=0;
in >> n;
for (i=1; i<=n; i++)
in >> puncte[i].x >> puncte[i].y;
for (i=1; i<=n; i++)
for (j=i+1; j<=n; j++){
drepte[++l].panta = (puncte[j].x-puncte[i].x) ? (double)(puncte[j].y-puncte[i].y)/(puncte[j].x-puncte[i].x) : INF;
drepte[l].c=(drepte[l].panta!=INF) ? puncte[i].y-drepte[l].panta*puncte[i].x : puncte[i].x;
}
sort (drepte+1, drepte+l+1, cmp);
drepte[l+1]={-INF, 0};
for (i=1; i<=l; i++){
sti=i;
dscz=0;
while (i<=l && drepte[i].panta==drepte[i+1].panta){ ///cat timp sunt paralele
li=i;
while (i<=l && drepte[i].c==drepte[i+1].c) i++; ///cat timp sunt identice
dscz+=(i-li+1)*(i-li)/2;
if (drepte[i].panta==drepte[i+1].panta) i++;
}
trapeze+=(i-sti+1)*(i-sti)/2-dscz;
}
out << trapeze;
}