Girlfriend

本文介绍了一道关于ZYT和ZFeT被女友施下魔法,他们必须保持与恋人的特定距离限制,而他们的生存空间形成两个几何体且可能有交集的问题。你需要计算这个相交区域的体积,以评估他们在10100年内可能的幸福指数。通过球体坐标和半径计算,理解了两球体相交体积的求解方法。
摘要由CSDN通过智能技术生成

链接:https://ac.nowcoder.com/acm/contest/11253/F
来源:牛客网
 

题目描述

ZYT and ZFeT are great PUAs and both have two girlfriends,but they never think that their girlfriends could be so great at magic.

One day, when ZYT and ZFeT were busy training PU skills,they suddenly found themselves spelled by their girlfriends.

And their girlfriends told them that they would be freed after 1010010^{100}10100 years .

After examining carefully , they found the mechanism of the spell:

  1. ZYT must keep the distance between himself and his lover A no less than k1k_1k1​ times the distance between himself and his lover B.
  2. ZFeT must keep the distance between himself and his lover C no less than k2k_2k2​ times the distance between himself and his lover D.

Let P1,P2P_1,P_2P1​,P2​ denote the positions of ZYT and ZFeT, so that is:

∣AP1∣≥k1∣BP1∣,∣CP2∣≥k2∣DP2∣|AP_1|\geq k_1 |BP_1|,|CP_2|\geq k_2|DP_2|∣AP1​∣≥k1​∣BP1​∣,∣CP2​∣≥k2​∣DP2​∣
 

As they immediately discovered:their available living places formed two geometric forms in space and they may has intersection inside.

Surely the intersection was far too enough for them to become more and more gay(I mean,happy) in these 1010010^{100}10100 years.

Wondered how gay they could be,they wanted to ask you the volume of of the intersection.

输入描述:

 

The first line of input contains a single integer T{T}T — the number of test cases.


Each test case consists of five lines:


The first four lines contains three integers (xi,yi,zi)(x_i,y_i,z_i)(xi​,yi​,zi​), denoting the coordinates of points A,B,C,D.


Then another line contains two integers k1,k2k_1,k_2k1​,k2​, described as above.

输出描述:

 

Output T{T}T lines denoting the answer of each test case, answer with an error less than 10−310^{-3}10−3 (relatively or absolutely) will be accepted.

示例1

输入

复制1 1 0 0 3 0 0 2 0 0 4 0 0 3 3

1
1 0 0
3 0 0
2 0 0
4 0 0
3 3

输出

复制0.262

0.262

备注:

 

T≤10000T\leq 10000T≤10000.For each test case, 0≤xi,yi,zi≤1000,1<k1,k2≤1000\leq x_i,y_i,z_i\leq 1000,1<k_1,k_2\leq 1000≤xi​,yi​,zi​≤1000,1<k1​,k2​≤100.

It's guaranteed that A,B,C,D share no duplicated position.

求两个球的交集

用一下大佬推出的公式

 

#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
const double pi = acos(-1);//cos(pi)=-1
double x[4],y[4],z[4];
double u1,u2;
void fun(double x1,double y1,double z1,double r1,double x2,double y2,double z2,double r2)
{
    double ans=0;//球心距离 
    double dis=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));//相离 
    if(dis>=r1+r2)  ans=0;//内含 
    else if (dis+r1<=r2) ans=(4.00/3.00)*pi*r1*r1*r1;
    else if(dis+r2<=r1)  ans=(4.00/3.00)*pi*r2*r2*r2;
    else//相交 
    {
        //求两球体相交的体积的板子
        double cos=(r1*r1+dis*dis-r2*r2)/(2.00*dis*r1);
        double h=r1*(1.00-cos);
        ans+=(1.00/3.00)*pi*(3.00*r1-h)*h*h;
        cos=(r2*r2+dis*dis-r1*r1)/(2.00*dis*r2);
        h=r2*(1.00-cos);
        ans+=(1.00/3.00)*pi*(3.00*r2-h)*h*h;
    }
        printf("%.3f\n",ans);
}
 int main()
 {
     int T;
     cin>>T;
     while(T--)
     {
        for(int i=0;i<4;i++)
        {
			cin>>x[i]>>y[i]>>z[i];
		}
        cin>>u1>>u2;
        double cx1,cy1,cz1,cr1,t;
        //算球1的坐标球心和半径 
        cx1=(u1*u1*x[1]-x[0])/(u1*u1-1);
        cy1=(u1*u1*y[1]-y[0])/(u1*u1-1);
        cz1=(u1*u1*z[1]-z[0])/(u1*u1-1);
        t=u1*u1*((x[1]*x[1])+(y[1]*y[1])+(z[1]*z[1]))-x[0]*x[0]-y[0]*y[0]-z[0]*z[0];
        t/=(u1*u1-1);
        cr1=sqrt(cx1*cx1+cy1*cy1+cz1*cz1-t);
        
		
        double cx2,cy2,cz2,cr2;//算球2的坐标球心和半径 
        cx2=(u2*u2*x[3]-x[2])/(u2*u2-1);
        cy2=(u2*u2*y[3]-y[2])/(u2*u2-1);
        cz2=(u2*u2*z[3]-z[2])/(u2*u2-1);
        t=u2*u2*((x[3]*x[3])+(y[3]*y[3])+(z[3]*z[3]))-x[2]*x[2]-y[2]*y[2]-z[2]*z[2];
        t/=(u2*u2-1);
        cr2=sqrt(cx2*cx2+cy2*cy2+cz2*cz2-t);
        fun(cx1,cy1,cz1,cr1,cx2,cy2,cz2,cr2);
    }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值