@2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛: D:Thinking-Bear magic(公式)

链接:https://www.nowcoder.com/acm/contest/163/D
来源:牛客网
 

In order to become a magical girl, Thinking-Bear are learning magic circle.
He first drew a regular polygon of N sides, and the length of each side is a.
He want to get a regular polygon of N sides, and the polygon area is no more than L.
He doesn't want to draw a new regular polygon as it takes too much effort.
So he think a good idea, connect the midpoint of each edge and get a new regular polygon of N sides.
How many operations does it need to get the polygon he want?

输入描述:

The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
The first line of each case contains three space-separated integers N, a and L (3 ≤ N ≤ 10, 1 ≤ a ≤ 100, 1 ≤ L ≤ 1000).

输出描述:

For each test case, output a single integer.

 

示例1

输入

复制

1
4 2 3

输出

复制

1

[题意]

正多边形,取每次边的中点构成新的正多边形, 不断取中点, 问第几次操作后,新的小正多边形面积恰好 <= L;

给定 边长 a;

 

[思路]

公式:  正多边形的面积 是 内部边中点构成的多边形 面积的 (Sin(\frac{\pi (n-2)}{2n} ) )^{2}

多边形边长为  an = 2R*Sin(\frac{\pi}{n}) , R 是正多边形半径,边心距 rnrn = R* Cos(\frac{\pi}{n})

多边形面积:  \frac{Pn*Rn}{2} = \frac{Sin( \frac{2\pi}{n}) *n*R^{2}}{2}  , 把 边长带入得: \frac{Sin( \frac{2\pi}{n}) *n*an^{2}}{8*Sin( \frac{\pi}{n})^{2}} ,

所以 暴力枚举 第几次时恰好小于 L

 

[代码]

#include <iostream>
#include <math.h>
#define PI acos(-1)
using namespace std;
const int maxn=1e7+10;
int main()
{
	int t;
	scanf("%d",&t);
	double n,a,l;
	while (t--)
	{
		scanf("%lf%lf%lf",&n,&a,&l);
		double s=sin(2*PI/n)*n*a*a/(8.0*sin(PI/n)*sin(PI/n));
		double v=sin(PI*(n-2)/(2*n))*sin(PI*(n-2)/(2*n));
		int cnt=0;
		for (int i=1;i<=maxn;i++)
		{
			if (s<=l)
				break;
			cnt++;
			s=s*v*1000.0/1000.0;
		}	
		printf("%d\n",cnt);
	}	
	return 0;
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值