2021牛客多校2 - Girlfriend(球体积交)
生活随笔
收集整理的這篇文章主要介紹了
2021牛客多校2 - Girlfriend(球体积交)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:點擊查看
題目大意:空間內有6個點,滿足 ∣P1A∣≥k1∣P1B∣,∣P2C∣≥k2∣P2D∣|P_1A|\ge k_1|P_1B|,|P_2C|\ge k_2|P_2D|∣P1?A∣≥k1?∣P1?B∣,∣P2?C∣≥k2?∣P2?D∣,求 P1,P2P_1,P_2P1?,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(球体积交)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CodeForces - 1553F P
- 下一篇: 2021牛客多校2 - WeChat W