UVA10432 Polygon Inside A Circle 的题解
洛谷传送门
UVA传送门
题目大意
求半径为 r r r 的圆的内接正 n n n 边形的面积。
思路
将正 n n n 边形分成 n n n 个三角形,每个三角形夹角就是 2 π n \dfrac{2\pi}{n} n2π,腰长就是 r r r,每个三角形的面积就是 $r^2 \times \sin\frac{2\pi}{n}\div 2 $。
所以正 n n n 边形的面积就是 $n \times r^2 \times \sin\frac{2\pi}{n}\div 2 $。
注意
-
此题对 π \pi π 的精度要求较高,要多打几位。
-
sin \sin sin 使用的是弧度制,要转换成 sin 2 π n \sin\frac{2\pi}{n} sinn2π。
代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <ctime>
#include <string>
#include <cstring>
#define lowbit(x) x & (-x)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO {
inline int read() {
register int x = 0, f = 1;
register char c = getchar();
while (c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
inline void write(int x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
return;
}
}
using namespace fastIO;
const double PI = 3.1415926535897932;// 定义π
int main() {
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
double r, n;
while(cin >> r >> n) { // 输入
printf("%.3lf\n",r * r * n * sin(2 * PI / n) / 2.0); // 输出公式
}
return 0;
}
484

被折叠的 条评论
为什么被折叠?



