#UVa:10195-The Knights Of The Round Table

灆洢 2016-03-15 01:35:32

計算其內切圓的半徑即可得解。

P.S. 注意如果三邊長總和為零要另外處理,不然會產生除以零的錯誤。

C++(0.000)

/*******************************************************/
/* UVa 10195 The Knights Of The Round Table            */
/* Author: Maplewing [at] knightzone.studio            */
/* Version: 2016/03/15                                 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
  double a, b, c;
  while( scanf("%lf%lf%lf", &a, &b, &c) != EOF ){
    if( a+b+c == 0 ){
      printf("The radius of the round table is: 0.000\n");
      continue;
    }

    double s = (a+b+c)/2;
    double area = sqrt(s*(s-a)*(s-b)*(s-c));
    double r = (2*area)/(a+b+c);
    printf("The radius of the round table is: %.3lf\n", r);
  }

  return 0;
}

發表迴響

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