CF_1C_AncientBerlandCircus
2016-03-20 23:26
411 查看
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
output
题目意思给一个正多边形的三个顶点组成的三角形
然后问这个正多边形的最小面积,即边数最少的正多边形
这个题目要求的有两个要点1多边形的外接圆半径
2多边形边数
因为多边形的外接圆与所给三角形外接圆一致
因此可以靠求面积(海伦公式,这里貌似用正弦定理过不了数据)然后正弦定理得到r
得到边数的方法比较奇特
首先要掌握一个新技术 小数的gcd
因为三角形的每边的圆心角一定是所对应正多边形每边圆心角的整数倍
因此这个gcd得出的就是多边形的圆心角
至于三角形边的圆心角由两个r和一边的三角形的余弦定理得出。
虽然结果保留6位
但是过程中gcd的精度却是十分敏感的,这里要注意
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
题目意思给一个正多边形的三个顶点组成的三角形
然后问这个正多边形的最小面积,即边数最少的正多边形
这个题目要求的有两个要点1多边形的外接圆半径
2多边形边数
因为多边形的外接圆与所给三角形外接圆一致
因此可以靠求面积(海伦公式,这里貌似用正弦定理过不了数据)然后正弦定理得到r
得到边数的方法比较奇特
首先要掌握一个新技术 小数的gcd
因为三角形的每边的圆心角一定是所对应正多边形每边圆心角的整数倍
因此这个gcd得出的就是多边形的圆心角
至于三角形边的圆心角由两个r和一边的三角形的余弦定理得出。
虽然结果保留6位
但是过程中gcd的精度却是十分敏感的,这里要注意
#include <iostream> #include <cstdio> #include <cmath> using namespace std; const double PI=acos(-1.0); //π的大小 const double eps=1e-2; //允许误差 int dcmp(double x) //误差修正 { if(fabs(x)<eps)return 0; if(x>0) return 1; return -1; } double dgcd(double a,double b) //小数的不精确最大公约数 { if(!dcmp(a)) return b; if(!dcmp(b)) return a; return dgcd(b,fmod(a,b)); //fmod返回x-n*y,符号同y。n=[x/y](向离开零的方向取整) } inline double sqr(double x) //平方 { return (x*x); } struct Point //点类,向量类 { double x,y; Point(){} Point(double a,double b):x(a),y(b){} void input() { scanf("%lf%lf",&x,&y); } friend Point operator +(const Point &a,const Point &b) //点之和 { return Point(a.x+b.x,a.y+b.y); } friend Point operator -(const Point &a,const Point &b) //点之差 { return Point(a.x-b.x,a.y-b.y); } double norm() //向量的模长 { return sqrt(sqr(x)+sqr(y)); } }; typedef Point Vector; //向量是点的别名 double dist(const Point &a,const Point &b) //点a与点b间距离 { return (a-b).norm(); } double cos_a(double a,double b,double c) { return acos((sqr(b)+sqr(c)-sqr(a))/(2*b*c)); } int main() { //freopen("1.in","r",stdin); Point a,b,c; a.input();b.input();c.input(); double AB=dist(a,b),AC=dist(a,c),BC=dist(b,c); double p=(AB+AC+BC)/2; double s=sqrt(p*(p-AB)*(p-AC)*(p-BC)); //三角形面积 double r=AB*AC*BC/4.0/s; //外接圆半径 double A=cos_a(BC,r,r),B=cos_a(AC,r,r); double C=2*PI-A-B; double O=dgcd(A,dgcd(B,C)); //cout<<A<<" "<<B<<" "<<C<<" "<<O<<endl; printf("%.6lf\n",r*r*sin(O)*PI/O); return 0; }
相关文章推荐
- 2541: 汽水瓶
- 将陆续回顾javaSE基础知识--通过圣思园张龙老师的视频
- 2016第11周日
- 20159217《网络攻防实践》第三周学习总结
- 交易前置系统专用工具类 常用工具类
- 归并排序
- 使用库函数API和C代码中嵌入汇编代码两种方式使用同一个系统调用
- hdu1176 免费馅饼--DP
- 永远不要忽视 "粉红色/红色的异样字体" 在你不知道为什么跟你期望偏差那么大的时候,,不要急记得去问问为什么
- POJ 3067 Japan (树状数组)
- linux 线程互斥同步By信号量
- LeetCode Counting Bits
- andrid线程学习
- 安卓基础之相关概念
- Struts 2设计者指南02:对象工厂
- 2016年3月14日作业
- typdef struct 用法介绍
- 二叉排序树(BST)构造与应用
- 八木天线仿真
- 再卑微的人或者动物,在孩子面前也是伟大的母亲!