六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 36|回复: 0

JOJ ACM 1184

[复制链接]

升级  98.33%

147

主题

147

主题

147

主题

举人

Rank: 3Rank: 3

积分
495
 楼主| 发表于 2013-2-4 22:14:37 | 显示全部楼层 |阅读模式
To calculate the circumference of a circle seems to be an easy task - provided you know its diameter. But what if you don't?

You are given the cartesian coordinates of three non-collinear points in the plane.
Your job is to calculate the circumference of the unique circle that intersects all three points.

Input Specification
The input file will contain one or more test cases. Each test case consists of one line containing six real numbers x1,y1, x2,y2,x3,y3, representing the coordinates of the three points. The diameter of the circle determined by the three points will never exceed a million. Input is terminated by end of file.
Output Specification
For each test case, print one line containing one real number telling the circumference of the circle determined by the three points. The circumference is to be printed accurately rounded to two decimals. The value of pi is approximately 3.141592653589793.
Sample Input
0.0 -0.5 0.5 0.0 0.0 0.50.0 0.0 0.0 1.0 1.0 1.05.0 5.0 5.0 7.0 4.0 6.00.0 0.0 -1.0 7.0 7.0 7.050.0 50.0 50.0 70.0 40.0 60.00.0 0.0 10.0 0.0 20.0 1.00.0 -500000.0 500000.0 0.0 0.0 500000.0
Sample Output
3.144.446.2831.4262.83632.243141592.65
code:
#include<stdio.h>#include<math.h>struct Point{  double x;  double y;}a[3];double SinA(){      double dist,high;     double A,B,C;      A = a[0].y-a[1].y;      B = a[1].x-a[0].x;      C = a[0].x*a[1].y-a[1].x*a[0].y;      high = fabs(A*a[2].x+B*a[2].y+C)/sqrt(A*A+B*B);      dist = sqrt(pow((a[0].x - a[2].x),2)+pow(a[0].y-a[2].y,2));    return high/dist;}int main(){      double c,ab;    while(scanf("%lf%lf%lf%lf%lf%lf",&a[0].x,&a[0].y,&a[1].x,&a[1].y,&a[2].x,&a[2].y)!=EOF){      ab = sqrt(pow((a[1].x - a[2].x),2)+pow(a[1].y-a[2].y,2));                c = ab * 3.141592653589793 / SinA();      printf("%.2lf\n",c);   }   return 0;}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表