codeforces 1C 计算几何
2017-11-09 17:38
507 查看
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
题意:给出三个点的下标,找出包含给定点的正多边形的最小面积.
题解:连接三个点构成一个三角形. 三角形的外接圆上的多个点构成最小正多边形的面积. 边越少面积越小, 找到外接圆的圆心与三角形三个点构成的三个角, 再求三个角的最大公约数,这个角就是多边形的其中一个角的大小.(正多边形与外接圆同圆心)就可以算出最小面积.
需要用到的几何知识:
已知三角形三条边求面积:海伦公式: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;
}
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
题意:给出三个点的下标,找出包含给定点的正多边形的最小面积.
题解:连接三个点构成一个三角形. 三角形的外接圆上的多个点构成最小正多边形的面积. 边越少面积越小, 找到外接圆的圆心与三角形三个点构成的三个角, 再求三个角的最大公约数,这个角就是多边形的其中一个角的大小.(正多边形与外接圆同圆心)就可以算出最小面积.
需要用到的几何知识:
已知三角形三条边求面积:海伦公式: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 613 A. Peter and Snow Blower(计算几何)
- Codeforces 8D Two Friends 三分+二分+计算几何
- Codeforces 560C Gerald's Hexagon【计算几何】
- CodeForces 281c Rectangle Puzzle 计算几何
- codeforces 223E 计算几何 图论 网络流思想
- CodeForces 614C Peter and Snow Blower【计算几何】
- Codeforces 849B - Tell Your World 【计算几何+思维】
- Codeforces 800B 计算几何
- 【CodeForces】257C - View Angle(计算几何)
- Codeforces 8D Two Friends 三分+二分+计算几何
- Codeforces 32E Hide-and-Seek 求2点关于镜面反射 计算几何
- codeforces 13D. Triangles(计算几何 dp)
- CodeForces 630 P. Area of a Star(计算几何)
- CodeForces - 1C:Ancient Berland Circus (几何)
- Codeforces 851C . Five Dimensional Points 计算几何,结论
- CodeForces 682 E.Alyona and Triangles(计算几何)
- codeforces 23D Tetragon 计算几何
- CodeForces 599 D.Randomizer(计算几何+期望)
- CodeForces 659 D. Bicycle Race(计算几何 + 数学公式)