思路
- 我们可以先求出正四面体的内切球半径和外接球半径
1)当r小于等于内切球半径时,此时不相交
2)当r大于等于外接球半径时,此时全部能喷到,结果为正四面体的表面积
3)当与正四面体的某一面相交结果为一个内含或内切圆时,结果为这个圆的面积*4(正四面体的面数)
4)如下图所示
代码
// Problem: 三棱锥之刻
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/9981/E
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp(aa,bb) make_pair(aa,bb)
#define _for(i,b) for(int i=(0);i<(b);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,b,a) for(int i=(b);i>=(a);i--)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define X first
#define Y second
#define lowbit(a) (a&(-a))
#define debug(a) cout<<#a<<":"<<a<<"\n"
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
const int N=100010;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-6;
const double PI=acos(-1.0);
void solve(){
ld a,r;cin>>a>>r;
ld minr=sqrt(6.0)/12*a,maxr=sqrt(6.0)/4*a;//内切球半径和外接球半径
if(r<=minr){
cout<<"0\n";
return;
}
if(r>=maxr){
cout<<sqrt(3.0)*a*a<<"\n";
return;
}
r=sqrt(r*r-minr*minr);
ld h=a/sqrt(3.0)/2;
if(r<=h){
cout<<4*PI*r*r<<"\n";
return;
}
ld theta=PI-asin(h/r);
// debug(theta/PI*180);
ld s1=sqrt(r*r-h*h)*h;
// debug(s1);
ld alpha=(PI/3-(5.0/6*PI-theta))*2;
ld s2=0.5*alpha*r*r;
// debug(s2);
cout<<(PI*r*r-3*(s2-s1))*4<<"\n";
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
// int t;cin>>t;while(t--)
solve();
return 0;
}

京公网安备 11010502036488号