题目描述

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 1010010100 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 k1k1 times the distance between himself and his lover B.
  2. ZFeT must keep the distance between himself and his lover C no less than k2k2 times the distance between himself and his lover D.

Let P1,P2P1,P2 denote the positions of ZYT and ZFeT, so that is:

∣AP1∣≥k1∣BP1∣,∣CP2∣≥k2∣DP2∣∣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 1010010100 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 TT — the number of test cases.Each test case consists of five lines:The first four lines contains three integers (xi,yi,zi)(xi,yi,zi), denoting the coordinates of points A,B,C,D.Then another line contains two integers k1,k2k1,k2, described as above.

输出描述:

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

示例1

输入

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

输出

0.262

题意: 给出三维空间四个点A、B、C、D的坐标,以及k1和k2,第一个人的活动范围是所有到A距离大于等于k1倍的到B距离的位置,第二个人的活动范围是所有到C距离大于等于k2倍的到D距离的位置,求二者活动范围交集的体积。

分析: 列出方程后可以发现每个人的活动范围都是一个球体,所以问题就转化为求两球体的体积交了,主要还是公式化简比较麻烦,当求出球心坐标和半径后就可以套用模板了。

具体代码如下:

#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 double long double
#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);
}void solve()
{double x[5],y[5],z[5];double x1, y1, z1, r1, x2, y2, z2, r2;for(int i=1;i<=4;i++) cin>>x[i]>>y[i]>>z[i];double k1,k2;cin>>k1>>k2;x1 = ((k1*k1*x[2]-x[1])/(k1*k1-1));y1 = ((k1*k1*y[2]-y[1])/(k1*k1-1));z1 = ((k1*k1*z[2]-z[1])/(k1*k1-1));r1 = (x1*x1+y1*y1+z1*z1-(k1*k1*(x[2]*x[2]+y[2]*y[2]+z[2]*z[2]))/(k1*k1-1)+(x[1]*x[1]+y[1]*y[1]+z[1]*z[1])/(k1*k1-1));r1 = sqrt(r1);k1 = k2;x[1] = x[3];y[1] = y[3];z[1] = z[3];x[2] = x[4];z[2] = z[4];y[2] = y[4];x2 = ((k1*k1*x[2]-x[1])/(k1*k1-1));y2 = ((k1*k1*y[2]-y[1])/(k1*k1-1));z2 = ((k1*k1*z[2]-z[1])/(k1*k1-1));r2 = (x2*x2+y2*y2+z2*z2-(k1*k1*(x[2]*x[2]+y[2]*y[2]+z[2]*z[2])/(k1*k1-1))+(x[1]*x[1]+y[1]*y[1]+z[1]*z[1])/(k1*k1-1));r2 = sqrt(r2);
//  printf("%Lf %Lf %Lf %Lf\n", x1, y1, z1, r1);
//  printf("%Lf %Lf %Lf %Lf\n", x2, y2, z2, r2);double v = sphere_intersect(x1, y1, z1, r1, x2, y2, z2, r2);printf("%Lf\n", v);
}
int main(){int _;scanf("%d",&_);while(_--) solve();return 0;
}/*
10
0 0 0
1 1 1
1 0 1
1 1 0
2 3
*/

[球体积交]Girlfriend 2021牛客多校第2场 F相关推荐

  1. bitset优化+滚动优化dp ----- 2021牛客多校第8场 F Robot

    题目大意: 就是给你一个大小为n∗mn*mn∗m的矩阵,里面有障碍物,每次询问给你一个机器人,以及机器人的起始位置,问你这个机器人能否从起点到终点 机器人有3种类型 只能往右走 只能往下走 可以往右走 ...

  2. 线段树 ---- 线段树维护线段相加+滑动变长窗口 2021牛客多校第7场 F xay loves trees

    题目大意: 给你两个大小相同的树但是形状不一定一样 叫你选出最大的子集,满足下面两个条件 在第一颗树上是一条链 在第二颗树上任意两个点都不是祖先关系 解题思路: 首先我们现在第二颗树上面把每个点的df ...

  3. 2021牛客多校第五场补题

    B-Boxes 链接:https://ac.nowcoder.com/acm/contest/11256/B 来源:牛客网 题目描述 There're nn_{}n​ boxes in front o ...

  4. 2021牛客多校第八场补题 D-OR

    链接:https://ac.nowcoder.com/acm/contest/11259/D 来源:牛客网 题目描述 There are two sequences of length n−1n-1n ...

  5. 2019牛客多校第三场 F.Planting Trees

    题目链接 题目链接 题解 题面上面很明显的提示了需要严格\(O(n^3)\)的算法. 先考虑一个过不了的做法,枚举右下角的\((x,y)\),然后二分矩形面积,枚举其中一边,则复杂度是\(O(n^3 ...

  6. 2019牛客多校第十场 F.Popping Balloons

    使用线段树,将(1,1+r,1+2r),(2,2+r,2+2r),(3,3+r,3+2r)以此类推,每个看成一个节点,对y进行建树,然后枚举x,维护最大值即可. 代码如下: #include<c ...

  7. 2019牛客多校第七场 F Energy stones 树状数组+算贡献转化模拟

    Energy stones 题意 有n块石头,每块有初始能量E[i],每秒石头会增长能量L[i],石头的能量上限是C[i],现有m次时刻,每次会把[s[i],t[i]]的石头的能量吸干,问最后得到了多 ...

  8. 【2021牛客多校2】F-Girlfriend 计算几何

    2021牛客多校2-F F-Girlfriend 题目大意 给出四个点 A , B , C , D A, B, C, D A,B,C,D 另有两点 P 1 , P 2 P_1, P_2 P1​,P2​ ...

  9. LCS(2021牛客多校4)

    LCS(2021牛客多校4) 题意: 让你构造三个字符串s1,s2,s3,长度均为n,要求LCS(s1,s2)=a,LCS(s2,s3)=b,LCS(s1,s3)=c 题解: 先考虑三个串互相LCS为 ...

最新文章

  1. Spring JDBC-使用Spring JDBC访问数据库
  2. LabelImg操作及快捷键
  3. Linux目录结构介绍
  4. 转-HTTPClient调用https请求,通过基本认证用户名密码(Basic Auth)
  5. Spring MVC集成测试
  6. flex 左右布局_移动端开发常用布局:前端弹性布局总结
  7. PowerDesigner生成的建表脚本中如何把对象的双引号去掉
  8. WordPress根目录(Root)
  9. html在线填空题,HTML测试题-(含答案).pdf
  10. 【车辆检测】基于matlab yolo v2车辆检测识别【含Matlab源码 581期】
  11. matlab进化树的下载,mega7进化树软件下载
  12. 机器人控制框架行为树py_trees <一、行为树介绍>
  13. STM32 USB Mass Storage 例程调试笔记
  14. ubuntu20.04系统安装u盘制作方法
  15. 使用python解析pdf文件
  16. C语言 生成随机数 srand用法 伪随机函数rand srand需不需要重新播种问题 srand该不该放在循环里
  17. 坐的越久,死的越快——说说工作环境
  18. 如何衡量一个量化策略的好坏
  19. HMI-48-【多媒体】Title界面实现 3
  20. 【08月01日】A股滚动市净率PB历史新低排名

热门文章

  1. 1007: A+B 输入输出练习VIII
  2. 赤城新千禧计算机学校,今天,千禧宝宝如约而至
  3. PPT总是处于“只读模式”可以这样解决
  4. android 网易新闻 登录界面,Android实现仿网易新闻主界面设计
  5. 计算机一打开就卡在更新失败,Win10更新系统卡住不动怎么办 Win10系统更新卡住不动解决方法...
  6. 关于vue路由模式导致微信jssdk授权问题的正确解决姿势
  7. 计算机网络术语sonet,SONET
  8. 5nm计算机cpu,芯片14nm、10nm、7nm、7nm、7nm、7nm有什么差别?
  9. Digital Asset与国际衍生品协会携手,布局智能合约在衍生品交易中的使用
  10. Linux运维常见面试题