POJ2242 The Circumference of the Circle(几何)
题目链接。
题目大意:
给定三个点,即一个任意三角形,求外接圆的周长。
分析:
外接圆的半径可以通过公式求得(2*r = a/sinA = b/sinB = c/sinC),然后直接求周长。
注意:
C++AC,G++WA。
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> using namespace std; const double PI = 3.141592653589793; typedef struct Point { double x, y; Point (double x=0, double y=0):x(x),y(y) {}; }Vector; 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 Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; } int main(){ double x1, y1, x2, y2, x3, y3, d; while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3) { Vector A(x2-x1, y2-y1), B(x3-x1, y3-y1), C(x3-x2, y3-y2); d = Length(C) / (fabs(Cross(A, B)) / Length(A) / Length(B)); printf("%.2lf\n", d*PI); } return 0; }