codeforces 1C 计算几何
来源:互联网 发布:淘宝暴力引流软件 编辑:程序博客网 时间:2024/05/29 09:38
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.0000001.000000 1.0000000.000000 1.000000
1.00000000
题意:给出三个点的下标,找出包含给定点的正多边形的最小面积.
题解:连接三个点构成一个三角形. 三角形的外接圆上的多个点构成最小正多边形的面积. 边越少面积越小, 找到外接圆的圆心与三角形三个点构成的三个角, 再求三个角的最大公约数,这个角就是多边形的其中一个角的大小.(正多边形与外接圆同圆心)就可以算出最小面积.
需要用到的几何知识:
已知三角形三条边求面积:海伦公式:s = (p * (p-a) * (p-b) * (p-c)); p = (a+b+c)/2;
已知三角形三条边和面积求外接圆的圆心:r =abc/4s;
余弦定理求角度:a^2 = b^2+c^2-2bccos(A);
浮点数求最大公约数需要用到fmod(),用于浮点数的取模.
要注意精度:1e-2和1e-4可以.1e-6精度太严格,会出现大的偏差.
代码:
#include<cstdio>#include<cstdlib>#include<iostream>#include<algorithm>#include<cstring>#include<stack>#include<queue>#include<deque>#include<map>#include<cmath>using namespace std;typedef long long ll;double caculatorNumber(double a, double b) {if(b - 0 <= 1e-2)return a;return caculatorNumber(b, fmod(a, b));}double caculatorDistance(double x1, double x2, double y1, double y2) { return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));}int main() { double point[3][2], dis[3], p, sum=0, area = 0, angle[3], r, res; res = acos(-1.0); for(int i = 0; i < 3; i++) scanf("%lf%lf", &point[i][0], &point[i][1]); for(int i = 0; i < 3; i++) { dis[i] = caculatorDistance(point[i][0], point[(i+1)%3][0], point[i][1], point[(i+1)%3][1]); sum += dis[i]; } p = sum/2; area = sqrt(p*(p-dis[0])*(p-dis[1])*(p-dis[2])); r = (dis[0]*dis[1]*dis[2])/(4*area); for(int i = 0; i < 3; i++) angle[i] = acos(1-dis[i]*dis[i]/(2*r*r)); angle[2] = 2*res-angle[0]-angle[1]; for(int i = 1; i < 3; i++) {angle[i] = caculatorNumber(angle[i-1], angle[i]); } printf("%.6lf\n", r*r*sin(angle[2])*res/angle[2]); return 0;}
- CodeForces 1C(计算几何)
- codeforces 1C 计算几何
- Codeforces 1C Ancient Berland Circus 计算几何
- CodeForces 281c Rectangle Puzzle 计算几何
- CodeForces 618 C. Constellation(计算几何)
- Codeforces 703C 思维or计算几何
- Codeforces 1C. Ancient Berland Circus(计算几何:正多边形性质+高精度)
- codeforces Round #1 C题 Ancient Berland Circus (计算几何)
- Codeforces Beta Round #1 C. Ancient Berland Circus (计算几何)
- CodeForces 614C Peter and Snow Blower【计算几何】
- CodeForces 274C|275E|The Last Hole!|计算几何
- Codeforces Round #365 (Div. 2) C 计算几何
- Codeforces 703C Chris and Road(计算几何)
- ☆ Codeforces 724C Ray Tracing 扩展欧几里得 + 计算几何
- 【CodeForces】257C - View Angle(计算几何)
- Codeforces 560C Gerald's Hexagon【计算几何】
- CodeForces 196 C.Paint Tree(计算几何+递归)
- Codeforces 851C . Five Dimensional Points 计算几何,结论
- TensorFlow下构建高性能神经网络模型的最佳实践
- Zookeeper启动异常:Error contacting service. It is probably not running.
- ssh免密登录
- 机器学习-随机森林(randomForest)模型的优化策略
- css3新增选择器
- codeforces 1C 计算几何
- unity3d配置Android环境,打包发布Apk流程详解
- 浅谈linux用户与用户组的概念
- List Contains方法使用问题
- 查看本机的系统字符集
- bzoj1196 [HNOI2006]公路修建问题(二分答案+kruskal/贪心)
- 数值的整数次方
- oracle一个创建用户、创建表空间、授权、建表的完整过程
- 《深入理解Java虚拟机》学习笔记(7)--Java内存模型与线程