2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-DThinking-Bear magic(数学题)

题目描述

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

给你一个正N多边形 , 边长为a ,如果他的面积大于L , 就将该正N多边形每条边的中点相连 , 构造一个新的正N多边形,再求他的面积 , 如果小于L了 , 输出需要进行这样操作的次数

将正多边形分成N个三角形 , 即求N个三角形的面积。 已知边和边所对的角度 , 易得面积

最终可以发现

S = a * (a/(2*tan(b/2))*1/2*N;

S1 = a *cos(b/2)*(a*cos(b/2)/(2*tan(b/2))*1/2*N;

可知每次变化a都是a = a * cos(b/2)

这里b = 2*Π / N;

#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1.0)
#define fa PI/N 
int main()
{
	int t;
	scanf("%d",&t);
	for(int T = 1 ; T <= t ; T++)
	{
		double L,N,a;
		cin>>N>>a>>L;
		double S = a*(a/(2*tan(fa)))/2*N;
		int ans = 0;
		while(1)
		{
			if(S - L <= 1e-5) break;
			a = a*cos(fa);
			S = a*(a/(2*tan(fa)))/2*N;
			ans++;
		}
		cout<<ans<<endl;
	}
}

猜你喜欢

转载自blog.csdn.net/qq_41593380/article/details/81474822