Cod sursa(job #528841)

Utilizator popoiu.georgeGeorge Popoiu popoiu.george Data 3 februarie 2011 16:05:57
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include<fstream>
#include<map>
#define inf "trapez.in"
#define outf "trapez.out"
#define NMax 1100
using namespace std;

fstream f(inf,ios::in),g(outf,ios::out);

struct punct { double x,y; };
punct p[NMax];
int N, perpendiculare;
map<double,int> H;

void read()
{
    f>>N; double x,y;
    for(int i=1; i<=N; i++)
    {
        f>>x>>y;
        p[i].x = x; p[i].y = y;
    }
}

void solve()
{
    for(int i=1; i<N; i++)
        for(int j=i+1; j<=N; j++)
            if( p[i].x == p[j].x ) perpendiculare++;
            else
            {
                double panta = (double)( (p[j].y-p[i].y)/(p[j].x-p[i].x) );
                if( H.find(panta) == H.end() ) H[panta] = 1;
                else H[panta]++;
            }
    int nr = perpendiculare*(perpendiculare-1)/2;
    for( map<double,int>::iterator it = H.begin(); it!=H.end(); it++ ) nr += (*it).second*( (*it).second-1 ) / 2;
    g<< nr;
}

int main()
{
	read(); solve();
	f.close(); g.close();
	return 0;
}