外切圆 UVA 11731 Ex-circles

来源:互联网 发布:360网络空间安全学院 编辑:程序博客网 时间:2024/05/03 05:36

Ex-circles

Input: Standard Input

Output: Standard Output

 

In the figure on the right you can see triangle ABC and its in-circle (Circle that touches all the sides of a triangle internally) and three ex-circles (Circles that touch one side internally and other two sides externally). D, E and F are centers of the ex-circles.

 

Given the length of the sides of triangle ABC, you will have to find the area of triangle DEF and also the total area of the three grey shaded regions.

 

Input

The input file can contain up to 6000 lines of inputs. Each line contains three positive integer numbers a, b, c which denotes the length of the sides of the triangle ABC. You can assume that these three sides can form a valid triangle (positive area) and none of the side length is greater than 1000.

 

Input is terminated by a line containing three zeroes.

 

Output

For each line of input produce one line of output. This line contains the serial of output followed by two floating-point numbers. The first one denotes the area of triangle DEF and second one denotes the total area of the three gray shaded regions. This floating-point numbers should have two digits after the decimal point. You can assume that small precision errors will not cause difference in the printed output.

 

Sample Input                             Output for Sample Input

3 4 5

10 11 12

0 0 0

Case 1: 30.00 21.62

Case 2: 211.37 144.73


Problem Setter: Shahriar Manzoor, Special Thanks: Sohel Hafiz



题意:很难解释。。。训练指南上面有。


思路:我不知道怎么样直接写出答案,我的思路是确定三个外切圆的圆心来确定答案。首先我们尝试考虑确定E的圆心,我们先从B引一条角平分线出来,不难发现,圆心一定在这条线上面,然后我们再有一条与AC平行是直线上下进行移动,当这条直线到AC的距离等于这条线与角平分线的交点到BC的距离相等时,这个是E的圆心。我不知道怎么直接用代数来做。。。由于平移的过程中距离都是会等比例的变大,那么当一定会有一点使得距离的差为0,而其他的为负数或者正数,所以我用二分来确定的。。。。脑子不好使没办法了。


代码:

#include<iostream>#include<cstdio>#include<string.h>#include<math.h>#include<cstring>#include<algorithm>using namespace std;#define eps 1e-10struct Point{Point (double xx=0,double yy=0) : x(xx) , y(yy) { }double x;double y;};typedef Point Vector;Vector operator+(Vector  v1,Vector  v2) { return Vector(v1.x+v2.x,v1.y+v2.y); }Vector operator-(Vector  v1,Vector  v2) { return Vector(v1.x-v2.x,v1.y-v2.y); }Vector operator*(Vector  v, double p) { return Vector(v.x*p,v.y*p); }Vector operator/(Vector  v,double p) { return Vector(v.x/p,v.y/p); }bool operator < (Point  a,Point  b) { return a.x < b.x || (a.x==b.x && a.y > b.y); }int dcmp(double x) {if (fabs(x) < eps) return 0;return x < 0 ? -1 : 1; }bool operator==(const Point & a,const Point & b) {return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;}double Dot(Vector  A,Vector  B) { return A.x*B.x+A.y*B.y; }double Length(Vector  A) { return sqrt(Dot(A,A)); }double Angle(Vector A,Vector B) { return acos(Dot(A,B)/Length(A)/Length(B)); }double Cross(Vector A,Vector B) { return A.x*B.y-A.y*B.x; }double Area2(Point a,Point b,Point c) {  return Cross(b-a,c-a); }Vector Rotate(Vector A,double rad) {return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));}Vector Normal(Vector A) { double L = Length(A); return Vector(-A.y/L,A.x/L); }//点和直线Point GetLineIntersection(Point P,Vector v,Point Q,Vector w){Vector u = P-Q;double t = Cross(w,u) / Cross(v,w);return P+v*t;}double DistanceToLine(Point P,Point A,Point B) {Vector v1 = B-A , v2 = P-A;return fabs(Cross(v1,v2))/Length(v1);}double DistanceToSegment(Point P,Point A,Point B){if (A==B) return Length(P-A);Vector v1 = B-A , v2 = P-A , v3 = P-B;if (dcmp(Dot(v1,v2)) < 0) return Length(v2);else if (dcmp(Dot(v1,v3)) > 0) return Length(v3);else return fabs(Cross(v1,v2))/Length(v1);}Point GetLineProjection(Point P,Point A,Point B) {Vector v = B-A;return A+v*(Dot(v,P-A)/Dot(v,v));}bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2) {double c1 = Cross(a2-a1,b1-a1) , c2 = Cross(a2-a1,b2-a1) ,     c3 = Cross(b2-b1,a1-b1) , c4 = Cross(b2-b1,a2-b1);return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4)<0;}bool OnSegment(Point p,Point a,Point b) {return dcmp(Cross(a-p,b-p))==0 && dcmp(Dot(a-p,b-p)) < 0;}//--------------------------------------------------------------------------------------------const double PI = 4*atan(1.0);double a , b , c , rf , re , rd;double ang;Point A , B , C , D , E , F;inline double sqr(double x) { return x*x; }Point CalCenter(Vector v,Point p,Point q,Point r,double left,double right,double & R) {double mid = left+(right-left)/2;while (dcmp(left-right)<0) {Point tmp = v*mid+p;double x = DistanceToLine(tmp,q,r);double y = mid*sin(ang);if (dcmp(x-y)==0) { R = x; return tmp; }else if (dcmp(x-y)<0) left = mid;else right = mid;mid = left+(right-left)/2;}R = left;return v*left+p;}bool isTriangle(int a,int b,int c) {if (a+b<=c) return false;if (a+c<=b) return false;if (b+c<=a) return false;return true;}int main(){int k = 0;while (scanf("%lf%lf%lf",&a,&b,&c)==3) {if (a+b+c==0) return 0;++k;ang = acos((sqr(a)+sqr(b)-sqr(c))/(2*a*b));B = Point(0,0);C = Point(a,0);A = Point(a-b*cos(ang),b*sin(ang));ang = Angle(C-B,A-B)*0.5;Vector HalfAngle = Rotate(C-B,ang);HalfAngle = HalfAngle/a;E = CalCenter(HalfAngle,B,A,C,Length(GetLineIntersection(B,HalfAngle,A,C-A)-B),1e5,re);ang = Angle(A-C,B-C)*0.5;HalfAngle = Rotate(A-C,ang)/b;F = CalCenter(HalfAngle,C,A,B,Length(GetLineIntersection(C,HalfAngle,B,A-B)-C),1e5,rf);ang = Angle(B-A,C-A)*0.5;HalfAngle = Rotate(B-A,ang)/c;D = CalCenter(HalfAngle,A,B,C,Length(GetLineIntersection(A,HalfAngle,B,C-B)-A),1e5,rd);double S = 0.5*Area2(D,E,F);double shade = 0.5*(rf*rf*Angle(E-F,D-F)+re*re*Angle(F-E,D-E)+rd*rd*Angle(F-D,E-D));printf("Case %d: %.2lf %.2lf\n",k,S,shade);}return 0;}




0 0
原创粉丝点击