Cod sursa(job #392662)

Utilizator cosmyoPaunel Cosmin cosmyo Data 7 februarie 2010 23:41:05
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include<fstream.h>
#include<algorithm>
#include<vector>
#define punct pair<double,double>
#define x first 
#define y second 
#include<math.h>
using namespace std;
const int nmax=1001;
vector<punct> a(nmax);
vector<double> v;
long n;
double cosinus(punct p1,punct p2)
{double d;
 d=sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
	return (double)(p2.y-p1.y)/d;
}
int main()
{long i,j,nrc=0,nr=0;
 double c,b;
 vector<double>::iterator it;
 ifstream fin("trapez.in");
  fin>>n;
   for(i=1;i<=n;i++)
	   fin>>a[i].x>>a[i].y;
  fin.close(); 
   a[n+1]=a[1];
   v.reserve(n*(n+1)/2+5);
  for(i=1;i<=n;i++)
	  for(j=i+1;j<=n;j++)
	   v.push_back(cosinus(a[i],a[j]));
	  v.push_back(cosinus(a[n],a[n+1]));
   stable_sort(v.begin(),v.end());
 ofstream fout("trapez.out");  
   for(it=v.begin();it!=(v.end()-1);it++)
    {c=*it;
     b=*(it+1);
	  if(fabs(c-b)<0.001)
	   nrc++;
	  else
	  {nr+=(nrc*(nrc+1)/2);
	   nrc=0;
	  }	   
	}
  fout<<nr;	
  fout.close();
return 0;
}