Cod sursa(job #2221315)

Utilizator Alex_AeleneiAlex Aelenei Ioan Alex_Aelenei Data 13 iulie 2018 18:08:05
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const double eps=1e-14;
const int INF=1e9;
class POINT 
{
private:
	int x,y;
public:
	POINT() 
	{
		x=0;
		y=0;
	}
	POINT(int _x,int _y) 
	{
		x=_x;
		y=_y;
	}
	POINT(const POINT &other) 
	{
		x=other.x;
		y=other.y;
	}
	void setp(int x1,int y1) 
	{
		x=x1;
		y=y1;
	}
	int getx() 
	{
		return x;
	}
	int gety() 
	{
		return y;
	}
	bool operator < (const POINT &other) {
	    
		if(x==other.x)
			return y<other.y;
		return x<other.x;
	}
	double panta(const POINT &other) 
	{
		if(x==other.x)return INF;
		return 1.0*(x-other.x)/(y-other.y);
	}
};
vector <POINT> v;
vector <double> pante;
int main() 
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
	int n,a,b,i,j;
	POINT temp;
	scanf("%d",&n);
	for(i=1; i<=n; ++i) 
    {
		scanf("%d%d",&a,&b);
		temp.setp(a,b);
		v.push_back(temp);
	}
	for(i=0; i<n-1; ++i)
		for(j=i+1; j<n; ++j)
			pante.push_back(v[i].panta(v[j]));
	sort(pante.begin(),pante.end());
	int l=1,ans=0;
	for(i=1;i<pante.size();++i) 
    {
        if(pante[i]==pante[i-1])
            ++l;
        else
        {
            ans+=l*(l-1)/2;
            l=1;
        }
    }
    printf("%d",ans);
	return 0;
}