链接http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1437
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<cmath>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-10;
struct date
{
double x,y;
}lt,rt,ml,mr;
inline double max( double a,double b ){return a>b?a:b;}
double work( date temp )
{
double a = mr.x - ml.x;
double b = pow(temp.x - ml.x,2) + pow(temp.y - ml.y,2);
double c = pow(temp.x - mr.x,2) + pow(temp.y - mr.y,2);
double res = (b+c-a*a)/(2.*sqrt(b)*sqrt(c));
return acos(res)*180/PI;
}
int main( )
{
date ans1,ans2; double res1,res2;
while( scanf("%lf%lf%lf",&ml.x,&mr.x,&mr.y) != EOF )
{
ml.y = mr.y;
scanf("%lf%lf%lf%lf",<.x,<.y,&rt.x,&rt.y);
double ang = 0;
if( lt.y == mr.y && lt.x >= ml.x && lt.x <= mr.x )
{
printf("180.00000000\n");
continue;
}
if( rt.y == mr.y && rt.x >= ml.x && rt.x <= mr.x )
{
printf("180.00000000\n");
continue;
}
if( lt.y == rt.y && lt.y == mr.y )
if( lt.x <= ml.x && rt.x >= mr.x )
{
printf("180.00000000\n");
continue;
}
while( abs(rt.x - lt.x) > 0.00000000001 || abs(rt.y - lt.y) > 0.00000000001 )
{
ans1.x = ( lt.x+lt.x+rt.x )/3.;
ans1.y = ( lt.y+lt.y+rt.y )/3;
ans2.x = ( rt.x+rt.x+lt.x )/3.;
ans2.y = ( rt.y+rt.y+lt.y )/3;
res1 = work(ans1); res2 = work(ans2);
if( res1 < res2 )
lt = ans1;
else rt = ans2;
ang = max( res1,res2 );
}
printf("%.8lf\n",ang);
}
return 0;
}