QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#246154 | #2839. 3D Geometry | nameless_story# | AC ✓ | 78ms | 3788kb | C++20 | 2.1kb | 2023-11-10 16:38:53 | 2023-11-10 16:38:54 |
Judging History
answer
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T1,class T2> bool cmin(T1 &x,const T2 &y) { if (y<x) { x=y; return 1; }return 0; }
template<class T1,class T2> bool cmax(T1 &x,const T2 &y) { if (x<y) { x=y; return 1; }return 0; }
#define all(x) (x).begin(),(x).end()
struct Vector
{
ll x,y,z;
Vector operator-(const Vector b)const
{
return {x-b.x,y-b.y,z-b.z};
}
};
long double vol(Vector o,Vector a,Vector b,Vector c)
{
Vector p=b-a,q=c-a;
ll A=p.y*q.z-p.z*q.y,B=p.z*q.x-p.x*q.z,C=p.x*q.y-p.y*q.x;
ll D=A*a.x+B*a.y+C*a.z;
// cerr<<A<<' '<<B<<' '<<C<<' '<<D<<'\n';
long double X=(D-B*o.y-C*o.z)/(long double)A-o.x,Y=(D-A*o.x-C*o.z)/(long double)B-o.y,Z=(D-B*o.y-A*o.x)/(long double)C-o.z;
if (X<0||Y<0||Z<0)
return 0;
else
return X*Y*Z/6;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
cout<<fixed<<setprecision(9);
Vector d;
while (cin>>d.x>>d.y>>d.z)
{
Vector a,b,c,e;
cin>>e.x>>e.y>>e.z;
// cin>>a.x>>a.y>>a.z;
// cin>>b.x>>b.y>>b.z;
// cin>>c.x>>c.y>>c.z;
int fx=0,fy=0,fz=0;
fx=e.x<d.x,fy=e.y<d.y,fz=e.z<d.z;
Vector p,q;
cin>>p.x>>p.y>>p.z;
cin>>q.x>>q.y>>q.z;
if (fx)
{
p.x=2*d.x-p.x;
q.x=2*d.x-q.x;
e.x=2*d.x-e.x;
}
if (fy)
{
p.y=2*d.y-p.y;
q.y=2*d.y-q.y;
e.y=2*d.y-e.y;
}
if (fz)
{
p.z=2*d.z-p.z;
q.z=2*d.z-q.z;
e.z=2*d.z-e.z;
}
a=d,b=d,c=d;
a.x=e.x,b.y=e.y,c.z=e.z;
if (p.x>q.x)
swap(p.x,q.x);
if (p.y>q.y)
swap(p.y,q.y);
if (p.z>q.z)
swap(p.z,q.z);
p.x=max(p.x,d.x);
p.y=max(p.y,d.y);
p.z=max(p.z,d.z);
q.x=min(q.x,e.x);
q.y=min(q.y,e.y);
q.z=min(q.z,e.z);
int flag=0;
if (p.x>q.x)
flag=1;
if (p.y>q.y)
flag=1;
if (p.z>q.z)
flag=1;
if (flag)
{
cout<<"0\n";
continue;
}
double ans=0;
for (int i=0; i<2; i++)
for (int j=0; j<2; j++)
for (int k=0; k<2; k++)
{
// cerr<<"GG\n";
ans+=(((i^j^k)&1)?(-1):(1))*vol({i?q.x:p.x,j?q.y:p.y,k?q.z:p.z},a,b,c);
}
cout<<max<long double>(0.0,ans)<<'\n';
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3636kb
input:
0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 2 2 2 0 0 0 1 1 1 0 2 0 2 0 2 1 0 1 0 1 0
output:
0.166666667 0.833333333 0.166666667
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 70ms
memory: 3784kb
input:
-3 -4 2 -5 -5 4 0 0 3 3 4 2 1 5 2 -4 0 0 5 -5 0 -2 -1 3 5 4 2 3 -5 -1 0 -2 -1 -4 -4 -3 -4 4 -2 -2 2 -1 2 2 1 4 0 5 -4 1 0 -5 -2 4 -5 2 -4 5 0 1 2 5 1 -1 0 -3 -1 5 -4 -4 2 -2 2 2 -4 1 3 -1 2 4 2 -2 1 3 2 5 2 -2 -3 -5 -1 0 0 5 4 2 2 5 3 -3 -3 -3 5 4 -4 1 2 -3 2 -4 2 -3 -2 -2 2 -2 -1 -4 -5 3 4 -3 -3 -3...
output:
0 0 0 0 0.708333333 0.000000000 0 15.355654762 0.000000000 6.562500000 0 0 0 0.000000000 0.000000000 0.000000000 0 0 0 0 0 1.319444444 0 0.526748971 4.650000000 0 0 0.000000000 1.925925926 0 0 0 0.000000000 0.000000000 15.868888889 0.093750000 0 0.000000000 0 0 0.000000000 0 0.000000000 0 0 0 0.2592...
result:
ok 100000 numbers
Test #3:
score: 0
Accepted
time: 69ms
memory: 3708kb
input:
-2 -2 -9 1 7 6 -3 -1 -4 -5 -6 2 -3 -4 -9 -10 -5 -4 0 2 -6 7 -9 2 6 4 5 -2 -6 0 8 -8 -3 -3 -10 2 10 -3 -8 -7 -5 -10 -9 -5 1 10 8 -1 7 9 10 6 3 9 -10 -10 -4 0 2 1 -2 4 9 10 5 -4 -6 6 3 7 4 8 6 5 2 3 -7 8 2 3 1 4 -10 7 -7 -3 -6 -10 5 -9 0 3 1 -5 -6 8 5 -3 8 -8 -8 -4 5 -10 4 0 3 1 9 -9 0 -8 8 -3 -7 9 -2...
output:
0 0 0 0 0 16.255732249 0.166666667 0 26.201923077 1.449891068 0 0 0 0 1.280276817 0 0 0 13.431240412 0 0.000000000 0 0.045454545 0 18.293333333 0 58.040816327 0.000000000 0 1.736111111 0.000000000 0 0 0 144.000000000 43.906250000 0.000000000 0.296712803 0 0 0 0 0.000000000 0 0.000000000 33.551038062...
result:
ok 100000 numbers
Test #4:
score: 0
Accepted
time: 63ms
memory: 3788kb
input:
91 49 27 -66 89 -21 -22 35 78 -64 41 -19 93 87 -92 72 -32 -67 -48 28 -6 -50 20 78 -33 90 41 75 -51 43 89 9 -89 -35 -73 88 13 13 82 82 -40 72 -21 -75 36 15 79 -66 -21 -99 -49 -33 60 78 -27 -86 -64 61 66 96 -77 37 -71 72 -35 -9 38 86 -68 51 65 15 -16 -64 -25 -72 23 81 -20 60 60 -52 -99 19 24 83 27 -11...
output:
0 0 391.127206881 0 28313.212264151 0 11477.662564207 4368.006677006 14406.483590596 5814.427201071 0 50112.716889796 0 0 0 0 0 0.000000000 0 38.151407055 0 0 0 0 0 72.201948734 0 0 0 0 0.000000000 0 0 1923.686957716 0 0 3977.938348638 0 0 0.000000000 185.220000000 0 0 6771.861224386 0 0 0 2386.2638...
result:
ok 100000 numbers
Test #5:
score: 0
Accepted
time: 78ms
memory: 3672kb
input:
-67 241 62 -271 -19 -199 364 487 343 293 433 -343 346 -321 78 -119 68 -487 -319 -45 -165 465 142 491 -310 476 -388 419 409 -124 167 -448 362 233 341 -119 9 -422 290 202 321 -217 310 216 286 172 10 -220 77 107 -282 352 -438 -26 171 81 111 -192 70 -132 376 -361 246 -371 354 -77 -400 -224 457 118 -387 ...
output:
0 417528.646965722 0 0.000000000 49064.274495413 5211742.513100332 3370766.246515173 0 0 84.405133541 165311.117708427 0 0.000000000 0 52736.152560963 0 132685.480972369 0 1436397.515315553 0 0 0 0 0 7356723.427007437 0 4878653.308295265 0 0 0 0 4575863.995235604 0 0 0 0 0 0 0 0 0 662108.378230373 0...
result:
ok 100000 numbers