CodeForces 281c Rectangle Puzzle 计算几何

You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.

Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.

Input

The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.

Output

In a single line print a real number — the area of the region which belongs to both given rectangles.

The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.

Sample test(s)
input
1 1 45
output
0.828427125
input
6 4 30
output
19.668384925





计算几何,分两种情况考虑

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main ()
{
	int x,y,z;
	double a,b,arf;
	//freopen("date.in","r",stdin);
	scanf("%d%d%d",&x,&y,&z);
	a=x;
	b=y;
	arf=z;
	
	double temp=max(a,b);
	b=min(a,b);
	a=temp;
	if(z==90) {printf("%f\n",b*b);return 0;}
	else if(z==180||z==0){
		printf("%f\n",a*b);
		return 0;
	}
	else {
		
		if(z>90)
		{
			arf=180.0-arf;
		}
		
		double tem=2*atan(b/a);
		double pi=acos(-1);
		arf=(arf*pi)/180.0;
		double g=tan(arf);
		double k=1.0/cos(arf);
		if(arf<tem)
		{
			double s1=(((1+k)*a-g*b)/((1+k)*(1+k)-g*g))*(((1+k)*a-g*b)/((1+k)*(1+k)-g*g))*g;
			double s2=(((1+k)*b-g*a)/((1+k)*(1+k)-g*g))*(((1+k)*b-g*a)/((1+k)*(1+k)-g*g))*g;
			double s=a*b;
			double ans=(s-s1-s2);
			printf("%.9f\n",ans);
		}
		else 
		{
			
			double ans=b*b/sin(arf);
			printf("%.9f\n",ans);
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值