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. 第一章:起步(python环境搭建)

    Python 环境搭建 学习python的第一步,就是要学习python开发环境的配置,在配置好python开发环境后,你需要再安装一款比较趁手的编辑器,事实上,python解释器本身就可以进行一些编 ...

  2. JDK的各个版本

    Java的各个版本 从上图我们看出,Java的版本名最开始以JDK开头,后来以j2se开头,最后到现在以Java开头,所以这些名字我们都可以说,但人们说的更多的是JDK多少,或者Java多少

  3. std::async的使用总结

    C++98标准中并没有线程库的存在,直到C++11中才终于提供了多线程的标准库,提供了管理线程.保护共享数据.线程间同步操作.原子操作等类.多线程库对应的头文件是#include <thread ...

  4. Go - httpclient 常用操作

    httpclient 模块介绍 httpclient 是基于 net/http  封装的 Go HTTP 客户端请求包,支持常用的请求方式.常用设置,比如: 支持设置 Mock 信息 支持设置失败时告 ...

  5. 深入理解SPI机制-服务发现机制

    https://www.jianshu.com/p/3a3edbcd8f24 SPI ,全称为 Service Provider Interface,是一种服务发现机制.它通过在ClassPath路径 ...

  6. Python基础(列表、元组)

    列表 在Python中列表用[]来表示,中间的元素可以是任何类型,用逗号分隔.列表是可变类型. 列表常用操作:增删改查. names = ["小明","小红", ...

  7. loj10087

    Southwestern Europe 2002,题面可参考 POJ 1201. 给定 n 个闭区间 [a_i,b_i] 和 n 个整数c_i .你需要构造一个整数集合Z ,使得对于任意i (1< ...

  8. CODEVS 2542单词__fail树

    2542 单词 2013年省队选拔赛天津市队选拔赛  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 大师 Master     题目描述 Description 小张最近在忙毕 ...

  9. Excel 如何实现以万为单位 保留两位小数 且不四舍五入

    数据科学交流群,群号:189158789,欢迎各位对数据科学感兴趣的小伙伴的加入! =TEXT(INT(I18/100)*1000,"0!.00,万") 将I18替换成你要转化的单 ...

  10. MariaDB数据库---主从复制,galera架构

    主从复制 补充一点:⑤slave端的IO thread 将从master端请求来的二进制日志文件中的内容存储到relay_log(中继日志)中 图片来源:https://www.cnblogs.com ...