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 数据库 模板文件 业务处理 ############## ...
随机推荐
- [noip模拟]分组行动
题目描述 最近,木木中学要举行一年一度的辩论赛了,我们活泼开朗乐观向上不寂寞不生病不挂科天天回家吃饭的新时代好少年--飞飞,自然是热情参与咯!辩论嘛,就有正方和反方两个组,这是一个传统项目,所以,包括 ...
- Django实现文件在本地的存储和读取
需求介绍:将图片存入本地的电脑文件夹中,将图片的路径保存到数据库,然后通过数据库的路径读取文件: 1.文件的存入: 前端文件: <form class="form-horizontal ...
- 【Android初级】使用setContentView实现页面的转换效果(附源码)
一提到Android中页面的切换,你是不是只想到了startActivity启动另一个Activity? 其实在Android中,可以直接利用setContentView达到类似页面转换效果的!实现思 ...
- 配置MySQL主从复制报错Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work
配置MySQL主从复制报错 ``` Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave ha ...
- token的分层图如下
基于 token 的多平台身份认证架构设
- loj10004智力大冲浪
题目描述 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者 m 元.先不要太高兴!因为这些钱还不一定都是你的?!接下来主持人宣布了比赛规则 ...
- TRUNK与VTP
TRUNK协议: 交换机之间VLAN通信: 同一个VLAN可以跨越多个交换机 主干功能支持多个VLAN的数据 Trunk(主干) VLAN 中交换机之间的链路:用来承载多个VLAN的数据流. Trun ...
- 五:SpringBoot-多个拦截器配置和使用场景
SpringBoot-多个拦截器配置和使用场景 1.拦截器简介 1.1 拦截器中应用 2.拦截器用法 2.1 编写两个拦截器 2.1.1 OneInterceptor 拦截器 2.1.2 TwoInt ...
- 函数式编程(logging日志管理模块)
本节内容 日志相关概念 logging模块简介 使用logging提供的模块级别的函数记录日志 logging模块日志流处理流程 使用logging四大组件记录日志 配置logging的几种方式 向日 ...
- C++泛型基础学习
转载http://blog.csdn.net/xinzheng_wang/article/details/6674847 泛型的基本思想:泛型编程(Generic Programming)是一种语言机 ...