Description
Input
Output
Sample Input
0.0 -0.5 0.5 0.0 0.0 0.5 0.0 0.0 0.0 1.0 1.0 1.0 5.0 5.0 5.0 7.0 4.0 6.0 0.0 0.0 -1.0 7.0 7.0 7.0 50.0 50.0 50.0 70.0 40.0 60.0 0.0 0.0 10.0 0.0 20.0 1.0 0.0 -500000.0 500000.0 0.0 0.0 500000.0
Sample Output
3.14 4.44 6.28 31.42 62.83 632.24 3141592.65
这道题我采用的是正弦定理;
一开始忘记自己算的是边长的平方,让我debug了好久;
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<string> #include<cmath> #define pi 3.141592653589793 using namespace std; struct Point { double x; double y; }; double dis(Point a,Point b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } int main() { Point point[3]; while(scanf("%lf %lf %lf %lf %lf %lf",&point[0].x,&point[0].y,&point[1].x,&point[1].y,&point[2].x,&point[2].y)!=EOF) { double a,b,c; a=dis(point[0],point[1]); b=dis(point[1],point[2]); c=dis(point[0],point[2]); double cosc; double R,ans; cosc=(a+b-c)/(2*sqrt(a)*sqrt(b)); //cout<<cosc<<endl; //cout<<acos(cosc)<<endl; //cout<<sin(acos(cosc))<<endl; R=sqrt(c)/(sin(acos(cosc))); ans=R*pi; printf("%.2lf\n",ans); } return 0; }