codeforces 1C (非原创)
2 seconds
64 megabytes
standard input
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.
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 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.
0.000000 0.000000
1.000000 1.000000
0.000000 1.000000
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 (非原创)的更多相关文章
- codeforces 6E (非原创)
E. Exposition time limit per test 1.5 seconds memory limit per test 64 megabytes input standard inpu ...
- Linux下high CPU分析心得【非原创】
非原创,搬运至此以作笔记, 原地址:http://www.cnitblog.com/houcy/archive/2012/11/28/86801.html 1.用top命令查看哪个进程占用CPU高ga ...
- CSS样式命名整理(非原创)
非原创,具体出自哪里忘了,如果侵害您的利益,请联系我. CSS样式命名整理 页面结构 容器: container/wrap 整体宽度:wrapper 页头:header 内容:content 页面主体 ...
- 非原创。使用ajax加载控件
非原创.来自博客园老赵. public class ViewManager<T> where T : System.Web.UI.UserControl { private System. ...
- Java 表达式解析(非原创)
因项目需要,在网上找来一套表达式解析方法,由于原来的方法太过于零散,不利于移植,现在整理在同一文件内: 文件中包含5个内部类,源码如下: import java.util.ArrayList; imp ...
- Java Interface 是常量存放的最佳地点吗?(转帖学习,非原创)
Java Interface 是常量存放的最佳地点吗?(转帖学习,非原创) 由于java interface中声明的字段在编译时会自动加上static final的修饰符,即声明为常量.因而inter ...
- 用RD,GR,BL三个方法内代码生成一张图片(非原创,我只是完整了代码)
我公开以下图片的源代码,,是ppm格式的,,自己找到能打开的工具.. (非原创,我加工的代码,可直接执行运行输出,缩略图能看到效果) 这是原博客 http://news.cnblogs.com/n/ ...
- tp5.1 phpspreadsheet- 工具类 导入导出(整合优化,非原创,抄一抄,加了一些自己的东西,)
phpspreadsheet-工具类 导入导出(整合优化,非原创,抄一抄,加了一些自己的东西)1. composer require phpoffice/phpspreadsheet2. 看最下面的两 ...
- Vue 仿QQ左滑删除功能(非原创)
非原创,摘选来源:http://www.jb51.net/article/136221.htm. 废话不多说,相当实用,先记录. Html代码: <div class="contain ...
- 老男孩Django笔记(非原创)
.WEB框架 MVC Model View Controller 数据库 模板文件 业务处理 MTV Model Template View 数据库 模板文件 业务处理 ############## ...
随机推荐
- Ubuntu安装Vivado
Step1 安装必要的库文件: sudo apt install libncurses5 build-essential openjdk-11-jdk Step2 进入vivado的安装文件夹 sud ...
- es6语法详解
什么是ECMAScript? ECMAScript是浏览器脚本语言的规范,而我们熟知的js语言,如JavaScript则是规范的具体实现.es6就好比Java的jdk. 一.es6语法详解:let声明 ...
- Py集合,字符串的格式化,函数,便利
可变与不可变 不可变指的是:重新赋值时,内存中的id值会变得 其中有:字符串,数字,元组 name="sb" v=id(name) print(v) name ="ale ...
- python 字典(formkey 建立 取值 赋值 删除 )
formkey快速建立空字典 result = {}.fromkeys(['name','age','job'],None) print(result) #往字典里添加元素 result. ...
- Dapper原来还可以直接这样写SQL,很强大哦
网络上对Dapper的解释是这样的: Dapper是一个简单的.NET对象映射器,在速度方面具有"King of Micro ORM"的头衔,几乎与使用原始的ADO.NET数据读取 ...
- SQL性能优化汇总
SQL效率低下也是导致性能差的一个非常重要的原因,可以通过查看执行计划看SQL慢在哪里,一般情况,SQL效率低下原因主要有: 类别 子类 表达式或描述 原因 索引 未建索引 无 产生全表扫描 未利 ...
- CF42A
题意 给定两个序列 a 和 b. 序列 a 中的各个数之间的比例可以得出一个 x . 当 b 中比例满足 a 中比例,即 \(b_1\):\(b_2\):\(b_3\)-- \(=\) \(a_1\) ...
- LOJ10162 骑士
ZJOI 2008 Z 国的骑士团是一个很有势力的组织,帮会中聚集了来自各地的精英.他们劫富济贫,惩恶扬善,受到了社会各界的赞扬. 可是,最近发生了一件很可怕的事情:邪恶的 Y 国发起了一场针对 Z ...
- IDEA中jdk设置
电脑运行环境是8, 但是IDEA提醒说1.5已经过时,IDEA中jdk设置还是比较麻烦 https://blog.csdn.net/u012365843/article/details/8138883 ...
- MongoTemplate聚合(一)$lookup
mongodb 最近入职了新的公司,新公司统一使用的mongodb,es等非关系型数据库.以前对es有一些了解,其实就是灵活的文档类型结构,不受限于关系型数据库的那种字段唯一确定的"死板 ...