NBOJv2 Problem 1009 蛤瑋的魔法(二分)

Problem 1009: 蛤瑋的魔法


Time Limits:  1000 MS   Memory Limits:  65536 KB

64-bit interger IO format:  %lld   Java class name:  Main


Description

爲了成爲魔法少女,蛤瑋正在學習畫魔法陣,他首先畫了一個正n邊形,查閱魔法書後蛤瑋發現書上要求魔法陣的面積不能超過L,他很頭疼,因爲用尺規作這個正n邊形花了他好大經歷,他不想重新畫一邊,於是他想了個好主意,把每條邊的中點依次連起來,就能得到一個縮小的正n邊行.現在蛤瑋想知道他需要按着個方法縮小多少次才能合乎魔法書上的要求.

 

Input

T(1<=T<=100),表示數據組數.

每組數據三個整數n(3<=n<=10),a(1<=a<=100),L(1<=L<=1000),其中a表示蛤瑋畫的正n邊行的邊長,n,L如題中描述.

數據保證[L-1e-5,L+1e-5]內答案唯一.

 

Output

每組數據輸出一個整數,表示蛤瑋操作的次數.

 

Sample Input

1
4 2 3

Output for Sample Input

1

Hint

Author

2016鄭州輕工業學院校賽

以前too naive,暴力模擬寫的,評測機估計比較快就過了……,實際上這題應該是二分

代碼:

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<stack>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define INF 0x3f3f3f3f
#define MM(x,y) memset(x,y,sizeof(x))
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
typedef pair<int,int> pii;
typedef long long LL;
const double PI=acos(-1.0);
double n,a,L,angle;
double area(const double &nn,const double &a)
{
	return n*a*a/(4*tan(PI/n));
}
double dpow(double a,int b)
{
	double r=1;
	while (b)
	{
		if(b&1)
			r*=a;
		a*=a;
		b>>=1;
	}
	return r;
}
int main(void)
{
	int tcase;
	int ans,mid,l,r;
	scanf("%d",&tcase);
	while (tcase--)
	{
		scanf("%lf%lf%lf",&n,&a,&L);
		angle=(n-2)*180/n;
		double rate=sin((angle/360)*PI);
		l=0,r=3000000;
		while (l<=r)
		{
			int mid=(l+r)>>1;
			double temp=area(n,a*dpow(rate,mid));
			if(temp<L)
			{
				r=mid-1;
				ans=mid;
			}	
			else
				l=mid+1;
		}
		printf("%d\n",ans);
	}
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章