Pagini recente » Cod sursa (job #709390) | Cod sursa (job #2178382) | Cod sursa (job #3268832) | Cod sursa (job #2721651) | Cod sursa (job #862084)
Cod sursa(job #862084)
#include <stdio.h>
#include <vector>
#include <map>
using namespace std;
int modul(int a){return a>0?a:(-1)*a;}
int cmmdc(int a,int b){return b==0?a:cmmdc(b,a%b);}
class Dreapta{
public : int y,x;
public: Dreapta(int x1,int y1,int x2,int y2){
if(x1>x2){
int aux=x1;x1=x2;x2=aux;
aux=y1;y1=y2;y2=aux;
}
y=y2-y1;
x=x2-x1;
int aux=cmmdc(modul(x),modul(y));
x/=aux;
y/=aux;
}
public: bool operator<(const Dreapta& other)const{if(x<other.x) return true;if(x==other.x) return y<other.y;return false;}
public: bool operator>(const Dreapta& other)const{if(x>other.x) return true;if(x==other.x) return y>other.y;return false;}
};
int main(){
freopen("trapez.in","r",stdin);
freopen("trapez.out","w",stdout);
int n,x,y;
vector<pair<int,int> > points;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d %d",&x,&y);
points.push_back(pair<int,int>(x,y));
}
map<Dreapta,int> drM;
for(int i=0;i<n-2;i++)
for(int j=i+1;j<n;j++){
drM[Dreapta(points[i].first,points[i].second,points[j].first,points[j].second)]++;
}
int nr=0;
for(map<Dreapta,int>::iterator it = drM.begin(); it!=drM.end();it++){
nr+=(it->second*(it->second-1))/2;
}
printf("%d",nr);
return 0;
}