Pagini recente » Cod sursa (job #2401955) | Cod sursa (job #1103939) | Cod sursa (job #2397529) | Cod sursa (job #95527) | Cod sursa (job #2455724)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
pair<int, int>p[1005];
pair<int, int>pa;
int n, s;
vector<pair<int, int>>fr;
int cmmdc(int x, int y)
{
if(y==0)
return x;
cmmdc(y, x%y);
}
int rez(int n)
{
return n*(n-1)/2;
}
int cmp(pair<int, int>a, pair<int, int>b)
{
return a.first*b.second<a.second*b.first;
}
int main()
{
freopen("trapez.in", "r", stdin);
freopen("trapez.out", "w", stdout);
scanf("%d", &n);
for(int i=1;i<=n;i++)
{
int x, y;
scanf("%d %d", &p[i].first, &p[i].second);
}
for(int i=1;i<n;i++)
for(int j=i+1;j<=n;j++)
{
pa.first=p[j].second-p[i].second;
pa.second=p[j].first-p[i].first;
int diviz=cmmdc(pa.first, pa.second);
pa.first/=diviz;
pa.second/=diviz;
fr.push_back({pa.first, pa.second});
}
sort(fr.begin(), fr.end(), cmp);
pair<int,int>x;
x.first=fr[0].first;
x.second=fr[0].second;
int nr=1;
for(int i=1;i<fr.size();i++)
{
if(fr[i].first==x.first && fr[i].second==x.second)
nr++;
else
{
s+=rez(nr);
x.first=fr[i].first;
x.second=fr[i].second;
nr=1;
}
}
printf("%d", s);
return 0;
}