三棱锥之刻(求三棱锥中心球与表面覆盖面积之和)

https://ac.nowcoder.com/acm/contest/9981/E

思路:

根据r和a的关系一共分4类情况:
①染色面积为0
②染色面积为4个圆形
③染色面积为三棱锥的内表面减去12个小三角(不是三角形,而是一个三角形往内刨掉一个弓形)
④染色面积为三棱锥的内表面全体


对于第三点我是这么求的,我没用出题人的方法。我是圆形-弓形面积。

弓形面积公式: 

 其中θ为圆心角, r为半径, a为弦长, h为圆心与弦构成的三角形的高。

球心到地面的距离是sqrt(6)*a/12;

剩下的根据高中基础的立体几何就可以算出来。

中间用到了一个tan(β/2),求角度的话用c++自带的反三角。

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5;
const double pi=3.1415926525;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  double a,r;cin>>a>>r;
  double dis=sqrt(6)*a/12;
  if(r<=dis){
    printf("%.7f\n",0.0);
  }
  else if(r*r<=a*a/8){///相切
    double r1=r*r-dis*dis;///底面圆半径的平方
    printf("%.7f\n",4*pi*r1);
  }
  else if(r*r>=9*a*a/24){
    printf("%.7f\n",sqrt(3)*a*a);
  }
  else{
    double r1=r*r-dis*dis;///底面圆半径的平方
    double h1=sqrt(3)*a/6;///p在底面上的点到正三角形的垂直距离
    double xian=sqrt(r1-h1*h1);///弦长的一半
    double s=4*( (pi*r1)-3*(atan(xian/h1)*r1-2*xian*h1/2 ) );
    printf("%.7f\n",s);
  }
return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值