Cod sursa(job #908830)

Utilizator enedumitruene dumitru enedumitru Data 10 martie 2013 00:20:12
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <fstream>
#include <algorithm> 
#define LL long long
using namespace std; 
ifstream f("trapez.in"); ofstream g("trapez.out"); 
const int Nmax=1002;
int n,m;
LL nr=1,tot;
struct art {LL x,y;} P[Nmax];
art C[Nmax*(Nmax-1)/2];
bool egal(art &a, art &b) 
{	return (a.x*b.y==b.x*a.y);}
bool cmp(const art &a, const art &b) 
{   if (a.x*b.y==b.x*a.y) return 0; 
    bool r=(a.x*b.y<b.x*a.y); 
    if (b.y<0) r=!r; 
    if (a.y<0) r=!r; 
    return r; 
} 
int main () 
{   f>> n;
	for(int i=1; i<=n; ++i) f>>P[i].x>>P[i].y; 
	for(int i=1; i<n; ++i) 
        for(int j=i+1; j<=n; ++j) 
			{C[++m].x=P[i].x-P[j].x; C[m].y=P[i].y-P[j].y;}
	sort(C+1,C+m+1,cmp);
	for(int i=2; i<=m; ++i) 
        if(egal(C[i-1],C[i])) ++nr; 
			else {tot += (nr*nr-nr)/2; nr=1;} 
    tot += (nr*nr-nr)/2; 
    g<<tot<<'\n'; g.close(); return 0; 
}