#UVa:438-The Circumference of the Circle

如下圖所示可得到公式,按照公式解即可。
438

C++(0.009)

/*******************************************************/
/* UVa 438 The Circumference of the Circle             */
/* Author: LanyiKnight [at] knightzone.org             */
/* Version: 2015/01/23                                 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

struct Point{
  double x;
  double y;
};

double getDistance(const Point &a, const Point &b){
  double xDistance = a.x - b.x;
  double yDistance = a.y - b.y;
  return sqrt(xDistance * xDistance + yDistance * yDistance);
}

int main(){
  const double PI = 3.141592653589793;

  Point points[3];
  while( scanf("%lf%lf%lf%lf%lf%lf", &(points[0].x), &(points[0].y),
                                     &(points[1].x), &(points[1].y),
                                     &(points[2].x), &(points[2].y)) != EOF ){
    double area = abs( points[0].x * points[1].y + 
                       points[1].x * points[2].y + 
                       points[2].x * points[0].y -
                       points[0].y * points[1].x -
                       points[1].y * points[2].x - 
                       points[2].y * points[0].x );

    double lines[3] = { getDistance(points[0], points[1]), 
                        getDistance(points[1], points[2]),
                        getDistance(points[2], points[0]) };
    double radius = lines[0] * lines[1] * lines[2] / (2 * area); 
    printf("%.2lf\n", 2 * radius * PI );
  }

  return 0;
}

沒有迴響

本文還沒有迴響,快來搶頭香!

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料