POJ 1813 Overlapped Shapes G++ 几何 圆与长方形的公共面积 没掌握

#include <iostream>
#include <cstdio>
#include <string> 
#include <cmath>
using namespace std;
//英语     看博友分析     抄博友程序       几何        圆与长方形的公共面积      没掌握    
double a[100];
double b[100];
double pi=acos(-1.0);//背 
double dis(double x1,double y1,double x2, double y2)
{
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double area(double x1, double y1,double x2,double y2,double r1,double r2)//抄博友程序
{
	double l=dis(x1,y1,x2,y2);
	if(l>=r1+r2)
	{
		return 0;
	}else if(l<=(r2-r1))//背 
	{
		return pi*r1*r1;
	}else if(l<=(r1-r2))//背 
	{
		return pi*r2*r2;
	}
	double q1=acos((r1*r1+l*l-r2*r2)/(2*r1*l));//背   余弦定理   
	double q2=acos((r2*r2+l*l-r1*r1)/(2*r2*l));
	return r1*r1*q1+r2*r2*q2-r1*l*sin(q1);//背   正弦定理  
} 
double inrec(double x1,double y1,double x2,double y2,double i,double j)
{
	return x1<=i&& i<=x2 && y1<=j && j<=y2;
}
bool incir(double x,double y, double r,double i, double j)//抄博友程序 
{
	return (x-i)*(x-i)+(y-j)*(y-j)<=r*r;
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		string op1,op2;
		cin>>op1;
		if(op1=="R")
		{
			cin>>a[0]>>a[1]>>a[2]>>a[3];
		}else if(op1=="C")
		{
			cin>>a[0]>>a[1]>>a[2];
		}
		cin>>op2;
		if(op2=="R")
		{
			cin>>b[0]>>b[1]>>b[2]>>b[3];
		}else if(op2=="C")
		{
			cin>>b[0]>>b[1]>>b[2];
		}
		if(op1=="C"&&op2=="C")
		{
			printf("%.0f\n",area(a[0],a[1],b[0],b[1],a[2],b[2]));
		}else//抄博友程序    背 
		{
			double ans=0;
			for(int i=0;i<=2000;i++)//抄博友程序 
			{
				for(int j=0;j<=2000;j++)
				{
					int ans1,ans2;
					if(op1=="R")
					{
						ans1=inrec(a[0]*200,a[1]*200,a[2]*200,a[3]*200,i,j);//抄博友程序   
					}else
					{
						ans1=incir(a[0]*200,a[1]*200,a[2]*200,i,j);
					}
					if(op2=="R")
					{
						ans2=inrec(b[0]*200,b[1]*200,b[2]*200,b[3]*200,i,j);
					}else
					{
						ans2=incir(b[0]*200,b[1]*200,b[2]*200,i,j);
					}
					if(ans1&&ans2)
					{
						ans=ans+0.005*0.005;//抄博友程序 
					}
				}
			}
			printf("%.0f\n",ans); 
		}
	}	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值