codeforces 1C 计算几何


                             C. Ancient Berland Circus
                          time limit per test  2 seconds
                          memory limit per test  64 megabytes
                          input  standard input  output  standard output

Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.

In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges.

Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time.

You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have.

Input

The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point.

Output

Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100.

Examples
Input
0.000000 0.000000
1.000000 1.000000
0.000000 1.000000
Output
1.00000000

题意:给出三个点的下标,找出包含给定点的正多边形的最小面积.

题解:连接三个点构成一个三角形. 三角形的外接圆上的多个点构成最小正多边形的面积. 边越少面积越小, 找到外接圆的圆心与三角形三个点构成的三个角, 再求三个角的最大公约数,这个角就是多边形的其中一个角的大小.(正多边形与外接圆同圆心)就可以算出最小面积.

需要用到的几何知识:

已知三角形三条边求面积:海伦公式:s = (p * (p-a) * (p-b) * (p-c)); p = (a+b+c)/2;

已知三角形三条边和面积求外接圆的圆心:r =abc/4s; 

余弦定理求角度:a^2 = b^2+c^2-2bccos(A);

浮点数求最大公约数需要用到fmod(),用于浮点数的取模.

要注意精度:1e-2和1e-4可以.1e-6精度太严格,会出现大的偏差.

代码:

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
double caculatorNumber(double a, double b) {
	if(b - 0 <= 1e-2)
		return a;
	return caculatorNumber(b, fmod(a, b));
}
double caculatorDistance(double x1, double x2, double y1, double y2) {
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
int main() {
    double point[3][2], dis[3], p, sum=0, area = 0, angle[3], r, res;
    res = acos(-1.0);
    for(int i = 0; i < 3; i++)
        scanf("%lf%lf", &point[i][0], &point[i][1]);
    for(int i = 0; i < 3; i++) {
        dis[i] = caculatorDistance(point[i][0], point[(i+1)%3][0], point[i][1], point[(i+1)%3][1]);
        sum += dis[i];
    }
    p = sum/2;
    area = sqrt(p*(p-dis[0])*(p-dis[1])*(p-dis[2]));
    r = (dis[0]*dis[1]*dis[2])/(4*area);
    for(int i = 0; i < 3; i++)
        angle[i] = acos(1-dis[i]*dis[i]/(2*r*r));
    angle[2] = 2*res-angle[0]-angle[1];
    for(int i = 1; i < 3; i++) {
		angle[i] = caculatorNumber(angle[i-1], angle[i]);
    }
    printf("%.6lf\n", r*r*sin(angle[2])*res/angle[2]);

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值