Pagini recente » Cod sursa (job #3280546) | Cod sursa (job #722612) | Cod sursa (job #3284416) | Cod sursa (job #2364383) | Cod sursa (job #2176151)
#include <fstream>
#include <math.h>
#include <algorithm>
using namespace std;
struct punct{int X;int Y;} Pct[1005];
struct perechi{int A;int B;} Panta[1005];
int N,i,j,A,B,Nrpante,Cmmdc,Nr,Raspuns;
int cmmdc(int A,int B)
{
int R;
while(B!=0) {R=A%B; A=B; B=R;}
return A;
}
bool ordonare(perechi X,perechi Y)
{
if(X.A<Y.A) return 1;
if(X.A==Y.A and X.B<Y.B) return 1;
return 0;
}
int main()
{
ifstream fin("trapez.in");
ofstream fout("trapez.out");
fin>>N;
for(i=1;i<=N;++i) fin>>Pct[i].X>>Pct[i].Y;
for(i=1;i<=N;++i)
for(j=i+1;j<=N;++j)
{
A=Pct[j].Y-Pct[i].Y;
B=Pct[i].X-Pct[j].X;
if(A<0) {A=-A; B=-B;}
if(!(A==0 and B==0))
{
Cmmdc=cmmdc(fabs(A),fabs(B));
A/=Cmmdc; B/=Cmmdc;
}
++Nrpante;
Panta[Nrpante].A=A;
Panta[Nrpante].B=B;
}
stable_sort(Panta+1,Panta+Nrpante+1,ordonare);
i=1;
while(i<=Nrpante)
{
Nr=1; j=i+1;
while(j<=Nrpante and Panta[j].A==Panta[i].A and Panta[j].B==Panta[i].B) {++j; ++Nr;}
i=j;
Raspuns+=(Nr-1)*Nr/2;
}
fout<<Raspuns;
fin.close ();
fout.close();
return 0;
}