Pagini recente » Cod sursa (job #2519991) | Cod sursa (job #2662038) | Cod sursa (job #1398109) | Cod sursa (job #249057) | Cod sursa (job #2114687)
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
int N, r;
pair<int, int> p[1001];
map<pair<int, int>, int> m;
void read()
{
//cin>>N;
ifstream f("trapez.in");
f>>N;
for (int i=0, x, y;i<N;i++)
{
//cin>>x>>y;
f>>x>>y;
p[i]={x, y};
}
}
int gcd(int a, int b)
{
if (a==0)
return b;
if (b==0)
return a;
int r=a%b;
while (r)
{
a=b;
b=r;
r=a%b;
}
return b;
}
void count_lines()
{
int x, y, z;
for (int i=0;i<N;i++)
{
for (int j=i+1;j<N;j++)
{
if (p[i].first==p[j].first)
m[{0,0}]++;
else
{
x=p[i].second-p[j].second;
y=p[i].first-p[j].first;
if (y<0)
y=-y, x=-x;
z=gcd(x, y);
x/=z;
y/=z;
m[{x,y}]++;
}
}
}
for (map<pair<int, int>,int>::iterator i=m.begin();i!=m.end();i++)
{
//cout<<'('<<(i->first).first<<' '<<(i->first).second<<") "<<i->second<<'\n';
r+=(i->second)*(i->second-1)/2;
}
}
void write()
{
//cout<<r;
ofstream g("trapez.out");
g<<r;
}
int main()
{
read();
count_lines();
write();
}