2021牛客多校2 - Girlfriend(球体积交)
Posted Frozen_Guardian
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021牛客多校2 - Girlfriend(球体积交)相关的知识,希望对你有一定的参考价值。
题目链接:点击查看
题目大意:空间内有6个点,满足 ∣ P 1 A ∣ ≥ k 1 ∣ P 1 B ∣ , ∣ P 2 C ∣ ≥ k 2 ∣ P 2 D ∣ |P_1A|\\ge k_1|P_1B|,|P_2C|\\ge k_2|P_2D| ∣P1A∣≥k1∣P1B∣,∣P2C∣≥k2∣P2D∣,求 P 1 , P 2 P_1,P_2 P1,P2 各自轨迹围成的空间体的体积交
题目分析:三维坐标系中两点之商为定值的话表示的是一个球壳,叫阿波罗尼斯球壳
囤个板子,求两球体积交的
代码:
// Problem: Girlfriend
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/11253/F
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
// #pragma GCC optimize(2)
// #pragma GCC optimize("Ofast","inline","-ffast-math")
// #pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
#include<list>
#include<unordered_map>
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
template<typename T>
inline void read(T &x)
{
T f=1;x=0;
char ch=getchar();
while(0==isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(0!=isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
x*=f;
}
template<typename T>
inline void write(T x)
{
if(x<0){x=~(x-1);putchar('-');}
if(x>9)write(x/10);
putchar(x%10+'0');
}
const int inf=0x3f3f3f3f;
const int N=1e6+100;
const double pi=acos(-1);
double pow2(double x){return x*x;}
double pow3(double x){return x*x*x;}
double dis(double x1,double y1,double z1,double x2,double y2,double z2)
{
return pow2(x1-x2)+pow2(y1-y2)+pow2(z1-z2);
}
double cos(double a,double b,double c){return (b*b+c*c-a*a)/(2*b*c);}
double cap(double r,double h){return pi*(r*3-h)*h*h/3;}
//2球体积交
double sphere_intersect(double x1,double y1,double z1,double r1,double x2,double y2,double z2,double r2)
{
double d=dis(x1,y1,z1,x2,y2,z2);
//相离
if(d>=pow2(r1+r2))return 0;
//包含
if(d<=pow2(r1-r2))return pow3(min(r1,r2))*4*pi/3;
//相交
double h1=r1-r1*cos(r2,r1,sqrt(d)),h2=r2-r2*cos(r1,r2,sqrt(d));
return cap(r1,h1)+cap(r2,h2);
}
//2球体积并
double sphere_union(double x1,double y1,double z1,double r1,double x2,double y2,double z2,double r2)
{
double d=dis(x1,y1,z1,x2,y2,z2);
//相离
if(d>=pow2(r1+r2))return (pow3(r1)+pow3(r2))*4*pi/3;
//包含
if(d<=pow2(r1-r2))return pow3(max(r1,r2))*4*pi/3;
//相交
double h1=r1+r1*cos(r2,r1,sqrt(d)),h2=r2+r2*cos(r1,r2,sqrt(d));
return cap(r1,h1)+cap(r2,h2);
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("data.in.txt","r",stdin);
// freopen("data.out.txt","w",stdout);
#endif
// ios::sync_with_stdio(false);
int w;
cin>>w;
double r1,r2,tmp1,tmp2;
double x[10],y[10],z[10];
double x1,x2,y1,y2,z1,z2;
while(w--) {
r1=0;
r2=0;
scanf("%lf%lf%lf",&x[2],&y[2],&z[2]);
scanf("%lf%lf%lf",&x[1],&y[1],&z[1]);
scanf("%lf%lf%lf",&x[4],&y[4],&z[4]);
scanf("%lf%lf%lf",&x[3],&y[3],&z[3]);
int k1,k2;
scanf("%d%d",&k1,&k2);
tmp1=(k1*x[1]+x[2])/(k1+1);
tmp2=(k1*x[1]-x[2])/(k1-1);
//cout << tmp1 << ' ' << tmp2 << endl;
x1=(tmp1+tmp2)/2;
r1+=(tmp1-tmp2)*(tmp1-tmp2);
tmp1=(k1*y[1]+y[2])/(k1+1);
tmp2=(k1*y[1]-y[2])/(k1-1);
y1=(tmp1+tmp2)/2;
r1+=(tmp1-tmp2)*(tmp1-tmp2);
tmp1=(k1*z[1]+z[2])/(k1+1);
tmp2=(k1*z[1]-z[2])/(k1-1);
z1=(tmp1+tmp2)/2;
r1+=(tmp1-tmp2)*(tmp1-tmp2);
r1=sqrt(r1)/2;
tmp1=(k2*x[3]+x[4])/(k2+1);
tmp2=(k2*x[3]-x[4])/(k2-1);
x2=(tmp1+tmp2)/2;
r2+=(tmp1-tmp2)*(tmp1-tmp2);
tmp1=(k2*y[3]+y[4])/(k2+1);
tmp2=(k2*y[3]-y[4])/(k2-1);
y2=(tmp1+tmp2)/2;
r2+=(tmp1-tmp2)*(tmp1-tmp2);
tmp1=(k2*z[3]+z[4])/(k2+1);
tmp2=(k2*z[3]-z[4])/(k2-1);
z2=(tmp1+tmp2)/2;
r2+=(tmp1-tmp2)*(tmp1-tmp2);
r2=sqrt(r2)/2;
printf("%.3f\\n",sphere_intersect(x1,y1,z1,r1,x2,y2,z2,r2));
}
return 0;
}
以上是关于2021牛客多校2 - Girlfriend(球体积交)的主要内容,如果未能解决你的问题,请参考以下文章