QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#762478 | #9704. Polycut | ucup-team1004 | RE | 1ms | 8104kb | C++17 | 4.5kb | 2024-11-19 15:10:16 | 2024-11-19 15:10:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int N=1e5+10;
const ld eps=1e-6;
int n,m,k;
struct vec{
ld x,y,z;
vec()=default;
vec(ld a,ld b,ld c):x(a),y(b),z(c){}
}a[N];
#ifdef DEBUG
ostream& operator << (ostream &out,vec a){
return out<<'('<<a.x<<','<<a.y<<','<<a.z<<')';
}
#endif
int sign(ld x){
return x>eps?1:(x<-eps?-1:0);
}
vec operator + (const vec &a,const vec &b){
return vec(a.x+b.x,a.y+b.y,a.z+b.z);
}
vec operator - (const vec &a,const vec &b){
return vec(a.x-b.x,a.y-b.y,a.z-b.z);
}
vec operator * (const vec &a,const ld &k){
return vec(a.x*k,a.y*k,a.z*k);
}
vec cross(const vec &a,const vec &b){
return vec(
a.y*b.z-a.z*b.y,
a.z*b.x-a.x*b.z,
a.x*b.y-a.y*b.x
);
}
ld dot(const vec &a,const vec &b){
return a.x*b.x+a.y*b.y+a.z*b.z;
}
ld normal(const vec &a){
return sqrt(dot(a,a));
}
struct plane{
int a,b,c,d;
vec arg()const{
return vec(a,b,c);
}
}b[4];
ld where(plane a,vec b){
return a.a*b.x+a.b*b.y+a.c*b.z-a.d;
}
vec calc(plane a,vec b,vec c){
ld x=where(a,b),y=-where(a,c);
return b*(y/(x+y))+c*(x/(x+y));
}
vector<pair<vec,int>>to[N];
vector<ld>ans;
ld volumn(int x,int y,int z,int w){
return dot(cross(a[y]-a[x],a[z]-a[x]),a[w]-a[x])/(ld)6;
}
void solve(vector<int>V,vector<pair<int,int>>E,int k){
if(!k){
vector<vec>cur;
for(int x:V)cur.push_back(a[x]);
// debug(cur);
// debug(V);
// debug(E);
int m=E.size();
vector<int>nex(m*2,-1),vis(m*2,0);
for(int i=0;i<m;i++){
auto [u,v]=E[i];
to[u].push_back({a[v]-a[u],i*2});
to[v].push_back({a[u]-a[v],i*2+1});
}
auto start=[&](int i){
if(i&1)return E[i/2].second;
else return E[i/2].first;
};
// debug(E);
for(int u:V){
// debug(u,to[u]);
vec z(0,0,0);
for(auto [p,id]:to[u]){
p=p*((ld)1/normal(p));
z=z+p;
}
z=z*((ld)1/to[u].size());
for(auto &[p,id]:to[u]){
p=p-z*(dot(p,z)/normal(z));
}
vec x=to[u][0].first;
vec y=cross(z,x);
auto find=[&](vec p){
int op=sign(dot(p,y));
if(op)return op>0?1:3;
return sign(dot(p,x))>0?0:2;
};
sort(to[u].begin()+1,to[u].end(),[&](pair<vec,int>a,pair<vec,int>b){
int p=find(a.first),q=find(b.first);
if(p!=q)return p<q;
return sign(dot(cross(a.first,b.first),z))>0;
});
// debug(u,to[u]);
// vector<int>cur;
for(int i=0;i<to[u].size();i++){
// cur.push_back(pb(to[u][i].second));
int j=(i+1)%to[u].size();
nex[to[u][j].second^1]=to[u][i].second;
}
// debug(u,cur);
}
// debug(nex);
ld res=0;
for(int i=0;i<m*2;i++)if(!vis[i]){
// vector<int>cur;
vis[i]=1;
for(int j=nex[i];;j=nex[j]){
// cur.push_back(start(j));
vis[j]=1;
if(vis[nex[j]])break;
res+=abs(volumn(V[0],start(i),start(j),start(nex[j])));
}
// debug(cur,res);
}
ans.push_back(res);
// debug(V,res);
// debug(E);
for(int u:V)to[u].clear();
// debug(res);
// exit(0);
return;
}
vector<int>Vl,Vr;
vector<pair<int,int>>El,Er;
vector<int>Vt;
for(int x:V){
int op=sign(where(b[k],a[x]));
if(op==0)Vt.push_back(x);
if(op>=0)Vl.push_back(x);
if(op<=0)Vr.push_back(x);
}
for(auto [u,v]:E){
if(sign(where(b[k],a[u]))<0)swap(u,v);
if(sign(where(b[k],a[u]))*sign(where(b[k],a[v]))<0){
a[++n]=calc(b[k],a[u],a[v]);
Vt.push_back(n),Vl.push_back(n),Vr.push_back(n);
El.push_back({n,u}),Er.push_back({n,v});
}else if(sign(where(b[k],a[u]))>=0){
El.push_back({u,v});
}else Er.push_back({u,v});
}
sort(Vt.begin()+1,Vt.end(),[&](int x,int y){
return sign(dot(cross(a[x]-a[Vt[0]],a[y]-a[Vt[0]]),b[k].arg()))>0;
});
for(int i=0;i<Vt.size();i++){
int j=(i+1)%Vt.size();
El.push_back({Vt[i],Vt[j]});
Er.push_back({Vt[i],Vt[j]});
}
solve(Vl,El,k-1);
solve(Vr,Er,k-1);
}
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1,x,y,z;i<=n;i++){
scanf("%d%d%d",&x,&y,&z);
a[i]=vec(x,y,z);
}
vector<pair<int,int>>E(m);
for(auto &[u,v]:E){
scanf("%d%d",&u,&v);
u++,v++;
}
for(int i=1;i<=k;i++){
scanf("%d%d%d%d",&b[i].a,&b[i].b,&b[i].c,&b[i].d);
}
vector<int>V(n);
iota(all(V),1);
solve(V,E,k);
// debug(ary(a,1,n));
sort(all(ans));
for(auto x:ans)printf("%.15Lf\n",x);
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8104kb
input:
8 12 1 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 1 3 3 2 2 0 4 5 5 7 7 6 6 4 0 4 1 5 2 6 3 7 3 0 0 1
output:
0.333333333333333 0.666666666666667
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 6876kb
input:
4 6 1 0 0 0 0 0 3 0 2 0 1 0 0 0 1 0 2 0 3 1 2 1 3 2 3 1 1 1 0
output:
0.000000000000000 1.000000000000000
result:
ok 2 numbers
Test #3:
score: -100
Runtime Error
input:
1549 3983 3 32 38 -38 -9 -29 -47 6 36 -51 0 37 -49 -31 26 -29 -29 -35 -23 24 -21 -54 -27 -18 55 31 -18 32 10 -3 54 -23 -33 50 -4 14 58 24 19 39 -15 57 22 46 12 -1 15 -24 -55 -42 15 -12 -36 15 -25 -40 -32 0 10 -37 -48 -34 -22 48 30 32 -46 12 -55 -28 -13 -49 -28 23 56 -6 31 7 -55 -7 -59 -16 17 -60 -2 ...