Cod sursa(job #69149)

Utilizator RobytzzaIonescu Robert Marius Robytzza Data 1 iulie 2007 14:56:34
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.4 kb
#include<fstream.h>
#include<math.h>
double a[1500],b[1500],xx,xx1,yy,yy1;
int N;
void citire(){
ifstream fin("triang.in");
fin>>N;
for (int i=0;i<N;i++)
   fin>>a[i]>>b[i];
fin.close();
}
double latura(double x1,double y1,double x,double  y){
double w=0;
w+=(x1-x);
w*=(x1-x);
w+=(y1-y)*(y1-y);
double f=sqrt(w);
return f;
}
void punct_trei (double L,int i,int j){
double L1=L*sqrt(3)/2;
double x1=a[i],x2=a[j],y1=b[i],y2=b[j];

if (y1-y2!=0)
xx=x1/2+x2/2+((y1-y2)/(L))*L1;
else
xx=x1/2+x2/2;

if (y2-y1!=0)
xx1=x2/2+x1/2+((y2-y1)/(L))*L1;
else
xx1=x2/2+x1/2;

if (x1-x2!=0)
yy=y1/2+y2/2+((x1-x2)/(L))*L1;
else
yy=y1/2+y2/2;

if (x2-x1!=0){
yy1+=((x2-x1)/(L))*L1;
yy1+=y1/2+y2/2;}
else
yy1=y1/2+y2/2;
}
int numarare (){
double L,L1,L2;
int nr=0;
for (int i=0;i<N-2;i++)
     for (int j=i+1;j<N-1;j++){
	 L=latura(a[i],b[i],a[j],b[j]);
	  punct_trei(L,i,j);
	 for (int y=j+1;y<N;y++){
	   if ((int)(a[y]*100)==(int)(xx*100)&&(int)(b[y]*100)==(int)(yy*100))
	       nr++;
	   else
	 if ((int)(a[y]*100)==(int)(xx1*100)&&(int)(b[y]*100)==(int)(yy1*100))
	    nr++;}}
	/*     if (a[y]<xx+0.1&&a[y]>xx-0.1&&b[y]<yy+0.1&&b[y]>yy-0.1)
			   nr++;
	     else
	       if (a[y]<xx1+0.1&&a[y]>xx1-0.1)
		if (b[y]<yy1+0.1&&b[y]>yy1-0.1)
		  nr++;  }}     */
return nr;
}
int main(){
citire();
ofstream fout("triang.out");
fout<<numarare();
fout<<"\n";
fout.close();
return 0;
}