CodeForce-1C Ancient Berland Circus

Ancient Berland Circus

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.0000001.000000 1.0000000.000000 1.000000

Output

1.00000000

题意:  给出三个点,以三个点为顶点的正多边形的最小面积思路:  三个点能围成一个愿,那么在圆内,边数越小面积越小,所以求边数最小的,  先求出边对应的圆心角,再求三个边圆心角的最大公约数知识相关:知道三边求面积,知道3边及面积求外接圆半径。

AC代码:
# include <iostream>
# include <cmath>
# include <cstdio>
using namespace std;
#define eqs 0.01
const double PI = acos(-1.0);

struct Point
{
	double x;
	double y;
};

Point operator-(Point v1, Point v2) // 向量相减
{
    v1.x -= v2.x;
    v1.y -= v2.y;
    return v1;
}

double dis(Point v) // 取模
{
    return sqrt(v.x * v.x + v.y * v.y);
}

double fgcd(double a, double b)
{
    return a < eqs ? b : fgcd(fmod(b,a), a);
}

int main()
{
	Point a, b, c;
	while(cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y)
	{
		double A = dis(a - b);
		double B = dis(b - c);
		double C = dis(a - c);
		// 求面积
		double p = (A + B + C) / 2.0 ;
		double s = sqrt(p * (p - A) * (p - B) * (p - C)) ;
		// 求半径
		double r = A * B * C / ( 4 * s );

		if(A > C)
			swap(A, C);
		if(B > C)
			swap(B, C);

		double angA = 2 * asin(A / (2 * r)) ;
		double angB = 2 * asin(B / (2 * r)) ;
		double angC = 2 * PI - angA - angB ;

		double g = fgcd(angC, fgcd(angA, angB));

		// 求内接正多边形面积
		double result = PI*r*r*sin(g)/g;
		printf("%.6lf\n", result);
	}

	return 0;
}
时间: 2024-10-24 09:33:25

CodeForce-1C Ancient Berland Circus的相关文章

CodeForces 1C Ancient Berland Circus

题意:给定三个点,求包含三点的正多边形最小面积: 思路:求圆心角最大公约数,多边形面积=每个小三角形面积和: #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<stack> #include<string> #include<map> #include<iostream> using namespace

Codeforces Beta Round #1 C. Ancient Berland Circus

果然Java还是不靠谱啊,一个NaN把我整了半天~~ 题目大意: 有一个正多边形,给出任意三个顶点的坐标,求这个正多边形的最小面积. 解题思路: 首先要知道这三个顶点组成的三角形的外接圆一定是这个正多边形的外接圆. 用过计算出三角形的三边长,可以计算出三角型面积,进而推出外接圆半径. 可以得到三个圆心角,找出最大公约数,那就是最大角度. 就可以计算出多边形面积了~~ 下面是代码: import java.text.DecimalFormat; import java.util.Scanner;

Ancient Berland Circus CodeForces - 1C

题意:给定一个正多边形的三个顶点,求这个正多边形的最小面积. 思路:首先,边数越小面积越小,所以只要确定出包含这三个顶点的边数最小的正多边形即可.这个三角形和正多边形外接同一个圆.所以先求出外接圆的半径,再求出三个圆心角,易得这个多边形的边所对应的圆心角可被这三个圆心角整除,所以三个圆心角的gcd就是多边形边所对的圆心角,然后2π除一下就得到是几边形,之后就可计算面积了 海伦公式: p=(a+b+c)/2,S=√p(p-a)(p-b)(p-c)(a,b,c为三角形的三边,S为三角形面积) 求外接

codeforces Round #1 C题 Ancient Berland Circus (计算几何)

这题的思路很好想,分成以下4步: 1:求外切园半径 2:求三个圆心角 3:求三个圆心角的最大公约数 4:最大公约数就是最大的正多边形内角,求面积即可. 但是每一步都不会求啊....sad...当想到第3步的时候甚至觉得应该用别的方法来求..要换方法..几何太渣了. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algo

codeforces--Ancient Berland Circus(三点确定最小多边形)

Ancient Berland Circus Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Appoint description:  System Crawler  (2015-01-06) Description Nowadays all circuses in Berland have a round arena with diameter 13 mete

CodeForces Beta Round #1

Codeforces Beta Round #1 A. Theatre Square [题意]一个n*m的矩形广场,用a*a的方形石板铺设,问最少需要多少块石板能铺满广场. [思路]水题,从n方向来看能能够铺设ceil(n/a)块,从m方向来看能能够铺设ceil(m/a)块,总共有ceil(n/a)*ceil(m/a)块. 1 /* 2 ** CodeForces 1A Theatre Square 3 ** Created by Rayn @@ 2014/05/18 4 */ 5 #inclu

Codeforces 1

A. Theatre Square: 题目地址:http://codeforces.com/contest/1/problem/A 题目大意:n*m的长方形用a*a的正方形覆盖,允许超出长方形,问需要几个正方形. 算法讨论:计算长和宽分别需要几个a,相乘即可. Code: #include <cstdio> #include <cmath> using namespace std; int n,m,a; int main(){ scanf("%d%d%d",&a

Old Berland Language

Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1,?l2,?...,?ln letters. Every word consisted of two letters, 0and 1. Ancient Berland people spoke quickly and didn't make pauses between the words,

CodeForces 37E Trial for Chief

Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Description Having unraveled the Berland Dictionary, the scientists managed to read the notes of the chroniclers of that time. For example, they learned how the chief of the