UVA10432 Polygon Inside A Circle 的题解

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 $。

注意

  1. 此题对 π \pi π 的精度要求较高,要多打几位。

  2. 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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值