Codeforces Beta Round #1 C. Ancient Berland Circus (计算几何)

来源:互联网 发布:javlibrary新域名17 编辑:程序博客网 时间:2024/05/29 14:51

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.0000001.000000 1.0000000.000000 1.000000
output
1.00000000
题解:有一个正多边形,给你其中三点的坐标,求这个多边形可能的最小面积,其中给出的三个点一定能够组成三角形。对于给定的三角形,其外接圆半径大小是唯一的;在外接圆半径大小唯一的情况下,要使正多边形面积最小,就是使正多边形的边数最少,也就是使得每条边所对应的圆心角最大。而最大圆心角 = 三角形三条边所对应的三个圆心角的公约数。然后再求出多边形的最小面积。

AC代码:

#pragma comment(linker, "/STACK:102400000,102400000")//#include<bits/stdc++.h>#include <stdio.h>#include <string.h>#include <algorithm>#include <iostream>#include <cstring>#include <vector>#include <map>#include <cmath>#include <queue>#include <set>#include <bitset>#include <iomanip>#include <list>#include <stack>#include <utility> using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int,int> pii;typedef vector<int> vi;const double eps = 1e-4;  const int INF = 1e9+7; const ll inf =(1LL<<62) ;const int MOD = 1e9 + 7;  const ll mod = (1LL<<32);const int N =1e6+6; const int M=100010;const int maxn=55555;#define mst(a) memset(a, 0, sizeof(a))#define M_P(x,y) make_pair(x,y)#define pi acos(-1.0)#define in freopen("in.txt","r",stdin) #define rep(i,j,k) for (int i = j; i <= k; i++)  #define per(i,j,k) for (int i = j; i >= k; i--)  #define lson  l , mid , rt << 1    #define rson  mid + 1 , r , rt << 1 | 1  const int lowbit(int x) { return x&-x; }//const int lowbit(int x) { return ((x)&((x)^((x)-1))); } int read(){ int v = 0, f = 1;char c =getchar();while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();}while(48 <= c && c <= 57) v = v*10+c-48, c = getchar();return v*f;}struct Point   {      double x,y;  };  double dist(Point p1,Point p2)  {      return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));  }  double Angle(double a,double b,double c)  {      return acos((a*a+b*b-c*c)/(2*b*a));  }  double gcd(double a,double b)  {      if(b+eps>0&&b-eps<0)//注意eps的范围         return a;      if(a+eps>0&&a-eps<0)          return b;      return gcd(b,fmod(a,b));  }int main()  {      Point p1,p2,p3;      while(~scanf("%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y))      {          double a,b,c,p,s,r;          double angle1,angle2,angle3,angle;          a=dist(p1,p2);          b=dist(p1,p3);          c=dist(p2,p3); //海伦公式         p=(a+b+c)/2;          s=sqrt(p*(p-a)*(p-b)*(p-c));                  r=a*b*c/(4*s); //外接圆半径                 angle1=Angle(r,r,a);          angle2=Angle(r,r,b);          angle3=2*pi-angle1-angle2;                  angle=gcd(angle1,gcd(angle2,angle3)); //求得三个圆心角∠1、∠2和∠3的最大公约数angle         double ans;          //求正多边形的面积        //正多边形一共有2*pi/angle个小三角形        ///每个小三角形的面积为r^2*sin(angle)/2        ans=0.5*r*r*sin(angle)*(2*pi/angle);          printf("%.6lf\n",ans);      }      return 0;  }  


2 0
原创粉丝点击