Pagini recente » Cod sursa (job #2573294) | Cod sursa (job #1267230) | Cod sursa (job #3179707) | Cod sursa (job #1490928) | Cod sursa (job #1725116)
#include <iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
struct pp
{
int a,b;
}v[10005],el,p1,p2;
vector<pp> vec;
int i,n,tot,k,fix,j;
bool comp(pp x,pp y)
{
if(x.a==y.a) return x.b<y.b;
return x.a<y.a;
}
int gcd(int x,int y)
{
if(x==0) return y;
if(y==0) return x;
if(x<0) x*=-1;
if(y<0) y*=-1;
while(x!=y)
{
if(x>y) x-=y;
else y-=x;
}
return x;
}
int main()
{
ifstream f("trapez.in");
ofstream g("trapez.out");
f>>n;
for(i=1;i<=n;i++)
{
f>>v[i].a>>v[i].b;
}
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
{
if(i!=j)
{
p1=v[i];p2=v[j];
if(p1.a<p2.a) swap(p1,p2);
fix=gcd(p1.a-p2.a,p1.b-p2.b);
el.a=(p1.a-p2.a)/fix;
el.b=(p1.b-p2.b)/fix;
vec.push_back(el);
}
}
sort(vec.begin(),vec.end(),comp);
for(i=1;i<vec.size();i++)
{
if(vec[i].a==vec[i-1].a&&vec[i].b==vec[i-1].b) k++;
else
{
tot+=(k+1)*(k)/2;
k=0;
}
}
g<<tot;
return 0;
}