ACM PKU Temple of Dune 2335 http://acm.pku.cn/JudgeOnline/problem?id=2335

#include <iostream>
#include <cmath>
using namespace std;
const double pi=3.1415926535897932384626;
double angle (double x0,double y0,double x1,double y1,double x2,double y2)
{
double t1,X1,X2,Y1,Y2,temp;
X1=x2-x0;
Y1=y2-y0;
X2=x1-x0;
Y2=y1-y0;
temp=(X1*X2+Y1*Y2)/(sqrt(X1*X1+Y1*Y1)*sqrt(X2*X2+Y2*Y2));
t1=acos(temp);
return t1;
}
double bngle (double x0,double y0,double x1,double y1,double x2,double y2)
{
double t2,X1,X2,Y1,Y2,temp;
X1=x2-x1;
Y1=y2-y1;
X2=x0-x1;
Y2=y0-y1;
temp=(X1*X2+Y1*Y2)/(sqrt(X1*X1+Y1*Y1)*sqrt(X2*X2+Y2*Y2));
t2=acos(temp);
return t2;
}
double cngle (double x0,double y0,double x1,double y1,double x2,double y2)
{
double t3,X1,X2,Y1,Y2,temp;
X1=x0-x2;
Y1=y0-y2;
X2=x1-x2;
Y2=y1-y2;
temp=(X1*X2+Y1*Y2)/(sqrt(X1*X1+Y1*Y1)*sqrt(X2*X2+Y2*Y2));
t3=acos(temp);
return t3;
}
double fgcd(double a, double b)
{
double t;
   if(a>b) 
   {
   t=a;
   a=b;
   b=t;
   }
   while(fmod(b,a)!=0)
{
   b=a;
   a=fmod(b,a);  
}
return b;
}
int main ()
{
int n;
cin>>n;
int i=0;
while (i!=n)
{
   double t1=0,t2=0,t3=0;
   double x[3]={0},y[3]={0};
   for (int j=0;j<3;j++)
   {
    cin >>x[j]>>y[j];
   }
   t1=2*angle(x[0],y[0],x[1],y[1],x[2],y[2]);
   t2=2*bngle(x[0],y[0],x[1],y[1],x[2],y[2]);
   t3=2*cngle(x[0],y[0],x[1],y[1],x[2],y[2]);
        double k1=fgcd(t1,t2);
               k1=fgcd(t3,k1);
               k1=fgcd(k1,2*pi);  
   cout<<2*pi/k1<<endl;        
   i++;
}
return 0;
}

posted on 2011-05-06 19:32  _Clarence  阅读(150)  评论(0编辑  收藏  举报

导航