Pagini recente » Cod sursa (job #72114) | Cod sursa (job #2833906) | Cod sursa (job #2391114) | Cod sursa (job #2269974) | Cod sursa (job #2606089)
// TrapezAgain.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
typedef pair<int, int> directie;
ifstream f("trapez.in");
ofstream g("trapez.out");
directie Create(directie a,const directie& b)
{
a.first-=b.first;
a.second-=b.second;
if (a.first == 0)
return { 0,1 };
if (a.second == 0)
return { 1,0 };
int g = __gcd(abs(a.first), abs(a.second));
if(a.first < 0)
{
a.first = -a.first;
a.second = -a.second;
}
return { a.first/g,a.second/g };
}
pair<int,int> puncte[1001];
directie dir[1000*1000+1];
int k;
int n;
int main()
{
f>>n;
for(int i=1;i<=n;i++)
f>>puncte[i].first>>puncte[i].second;
for(int i=1;i<n;i++)
for(int j=i+1;j<=n;j++)
dir[k++] = Create(puncte[i],puncte[j]);
sort(dir,dir+k);
int sol = 0;
int last = 0;
for(int i=1;i<k;i++)
if(dir[last] != dir[i])
{
int nr = i - last;
sol += nr*(nr-1)/2;
last = i;
}
int nr = k - last;
sol += nr*(nr-1)/2;
g<<sol;
f.close();
g.close();
}