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

题目大意:给出三个点,求出以这三个点为定点的最小正多边形。

求最小正多边形,边数越多,面积越大,所以要是求得的多边形的边尽量的小。

由三个点组成的三角形,可以确定一个外接圆,那么正多边形的所有的定点应该都在圆上,求出三边对应的圆心角,找出圆心角的最大公约数,也就得到了多边形的最小的边数。

防止钝角的情况,边长最长的对应的圆心角 = 2*PI - 其他两个圆心角。

r=a*b*c/(4*s)求出外接圆的面积,然后通过正弦定理求出三角形三个边各自的圆心角,然后利用求gcd函数求出A,B,C最大公约数。

由于三角形每条边所对应的圆心角都是正多边形圆心角的整数倍,故n=2*pi/gcd(A,B,C),然后正多边形的面积便是n个相同的三角形的面积了,其中每个三角形面积为r*r/2*sin(p),正多边形面积即可求出.

即:   S =  2*PI/p * 1/2*r*r*sin(p) =  PI*r*r*sin(p)/p

附代码:

 1 #include <cstdio>
2 #include <cstring>
3 #include <cmath>
4 #include <algorithm>
5 using namespace std ;
6 const double PI = acos(-1.0);
7 const double eqs = 0.01;
8 double gcd(double a,double b)
9 {
10 return a < eqs ? b : gcd(fmod(b,a),a);
11 }
12 int main()
13 {
14 double x1 , y1 , x2 , y2 , x3 , y3 ;
15 double a , b , c , p , s , r , k ;
16 double A , B , C ;
17 scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3) ;
18 a = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) ;
19 b = sqrt( (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3) ) ;
20 c = sqrt( (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3) ) ;
21 p = ( a + b + c ) / 2.0 ;
22 s = sqrt( p * (p-a) * (p-b) * (p-c) ) ;
23 r = a * b * c / ( 4 * s ) ;
24 if( a > c )
25 {
26 k = a ; a = c ; c = k ;
27 }
28 if( b > c )
29 {
30 k = b ; b = c ; c = k ;
31 }
32 A = 2 * asin(a/(2*r)) ; //正弦定理
33 B = 2 * asin(b/(2*r)) ;
34 C = 2 * PI - A - B ;
35 //printf("%lf %lf %lf\n", A, B, C) ;
36 p = gcd(A,B);
37 p = gcd(p,C) ;
38 //printf("%lf %lf\n", r, p) ;
39 printf("%.6lf\n", PI*r*r*sin(p)/p ) ;//1/2*a*b*sinc 三角形已知两边一角的面积公式
40 return 0;
41 }

参考博客:http://blog.csdn.net/winddreams/article/details/42532203

codeforces 1C (非原创)的更多相关文章

  1. codeforces 6E (非原创)

    E. Exposition time limit per test 1.5 seconds memory limit per test 64 megabytes input standard inpu ...

  2. Linux下high CPU分析心得【非原创】

    非原创,搬运至此以作笔记, 原地址:http://www.cnitblog.com/houcy/archive/2012/11/28/86801.html 1.用top命令查看哪个进程占用CPU高ga ...

  3. CSS样式命名整理(非原创)

    非原创,具体出自哪里忘了,如果侵害您的利益,请联系我. CSS样式命名整理 页面结构 容器: container/wrap 整体宽度:wrapper 页头:header 内容:content 页面主体 ...

  4. 非原创。使用ajax加载控件

    非原创.来自博客园老赵. public class ViewManager<T> where T : System.Web.UI.UserControl { private System. ...

  5. Java 表达式解析(非原创)

    因项目需要,在网上找来一套表达式解析方法,由于原来的方法太过于零散,不利于移植,现在整理在同一文件内: 文件中包含5个内部类,源码如下: import java.util.ArrayList; imp ...

  6. Java Interface 是常量存放的最佳地点吗?(转帖学习,非原创)

    Java Interface 是常量存放的最佳地点吗?(转帖学习,非原创) 由于java interface中声明的字段在编译时会自动加上static final的修饰符,即声明为常量.因而inter ...

  7. 用RD,GR,BL三个方法内代码生成一张图片(非原创,我只是完整了代码)

    我公开以下图片的源代码,,是ppm格式的,,自己找到能打开的工具.. (非原创,我加工的代码,可直接执行运行输出,缩略图能看到效果)  这是原博客 http://news.cnblogs.com/n/ ...

  8. tp5.1 phpspreadsheet- 工具类 导入导出(整合优化,非原创,抄一抄,加了一些自己的东西,)

    phpspreadsheet-工具类 导入导出(整合优化,非原创,抄一抄,加了一些自己的东西)1. composer require phpoffice/phpspreadsheet2. 看最下面的两 ...

  9. Vue 仿QQ左滑删除功能(非原创)

    非原创,摘选来源:http://www.jb51.net/article/136221.htm. 废话不多说,相当实用,先记录. Html代码: <div class="contain ...

  10. 老男孩Django笔记(非原创)

    .WEB框架 MVC Model View Controller 数据库 模板文件 业务处理 MTV Model Template View 数据库 模板文件 业务处理 ############## ...

随机推荐

  1. postgres模糊匹配大杀器

    ArteryBase-模糊匹配大杀器 问题背景 随着pg越来越强大,abase目前已经升级到5.0(postgresql10.4),目前abase5.0继承了全文检索插件(zhparser),使用全文 ...

  2. 我为什么不鼓吹 WireGuard

    原文链接:https://fuckcloudnative.io/posts/why-not-wireguard/ 最近有一款新型 VPN 工具备受瞩目,相信很多人已经听说过了,没错就是 WireGua ...

  3. centos6-centos7防火墙(iptables-firewalld)设置端口nat转发

    背景: 将本机的 8080端口转发至其他主机,主机 IP:192.168.1.162,目标主机 IP和端口192.168.1.163:80,方法如下: centos6系统iptables环境下: ip ...

  4. C#高级编程第11版 - 第二章 索引

    [1]2.1.1 Hello,World! 1. using static System.Console; // ... WriteLine("Hello World!"); 提前 ...

  5. Java并发包源码学习系列:阻塞队列实现之PriorityBlockingQueue源码解析

    目录 PriorityBlockingQueue概述 类图结构及重要字段 什么是二叉堆 堆的基本操作 向上调整void up(int u) 向下调整void down(int u) 构造器 扩容方法t ...

  6. MySQL主从配置This operation cannot be performed with a running slave io thread; run STOP SLAVE IO_THREAD FOR CHANNEL '' first.

    MySQL主从配置This operation cannot be performed with a running slave io thread; run STOP SLAVE IO_THREAD ...

  7. DPDK CAS(compare and set)操作

    前言 rte_ring是一个无锁队列,无锁队列的出队入队操作是rte_ring实现的关键.因此,本文主要讲解dpdk是怎样使用无锁机制实现rte_ring的多生产者入队操作. rte_atomic32 ...

  8. Tensorflow-卷积神经网络CNN

    卷积神经网络CNN 结构 池化操作 手写数字-卷积神经网络实现 import tensorflow as tf from tensorflow.examples.tutorials.mnist imp ...

  9. Jumpserver-堡垒机

    Jumpserver-堡垒机 1.基于Docker搭建Jumpserver堡垒机 1.1 下载镜像 1.2 运行镜像 1.2.1 官网步骤-Docker快速启动 1.3 浏览器访问 2.Jumpser ...

  10. SSM框架搭建详细解析

    总结了一下搭建SSM框架流程,在以后用到的时候方便回头使用. 使用工具:MyEclipse 2015:Tomcat 8版本:jdk1.8版本. 首先: 1:创建一个WebProject项目,jdk1. ...