QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#926921 | #7862. Land Trade | Brno (Bocheng Jiang, Zhenyu Wang, Taixiang Wang) | AC ✓ | 2629ms | 17368kb | C++20 | 6.6kb | 2025-03-06 14:40:58 | 2025-03-06 14:40:59 |
Judging History
answer
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define poly vector<node>
typedef long long ll;
typedef double ld;
using namespace std;
const int N=1000010,INF=0x3f3f3f3f;
const ld eps=1e-9,pi=acos(-1),inf=1e18;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
int dcmp(ld x){return x<-eps?-1:(x>eps?1:0);}
struct node{
ld x,y;
node(ld xx=0,ld yy=0){x=xx,y=yy;}
bool operator <(const node &a)const{return dcmp(x-a.x)?x<a.x:y<a.y;}
bool operator ==(const node &a)const{return !dcmp(x-a.x)&&!dcmp(y-a.y);}
node &operator +=(const node &b){x+=b.x,y+=b.y;return *this;}
node &operator -=(const node &b){x-=b.x,y-=b.y;return *this;}
node &operator *=(const ld &b){x*=b,y*=b;return *this;}
node &operator /=(const ld &b){x/=b,y/=b;return *this;}
friend istream &operator >>(istream &is,node &a){return is>>a.x>>a.y;}
friend ostream &operator <<(ostream &os,node &a){return os<<'('<<a.x<<','<<a.y<<')';}
}O(0,0);
ld lx,rx,ly,ry;
node operator +(const node &a,const node &b){return node(a.x+b.x,a.y+b.y);}
node operator -(const node &a,const node &b){return node(a.x-b.x,a.y-b.y);}
node operator *(const ld &x,const node &a){return node(x*a.x,x*a.y);}
node operator /(const node &a,const ld &x){return node(a.x/x,a.y/x);}
ld operator *(const node &a,const node &b){return a.x*b.x+a.y*b.y;}
ld operator ^(const node &a,const node &b){return a.x*b.y-a.y*b.x;}
ld sqr(ld x){return x*x;}
ld len(node a){return sqrt(a*a);}
ld dist(node a,node b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
node normal(node a){return node(-a.y,a.x);}
bool rectangle(node a){
return lx-eps<=a.x&&a.x<=rx+eps&&ly-eps<=a.y&&a.y<=ry+eps;
}
bool contain(node a,node b,node c){
node x=a-b,y=c-b;
return (!dcmp(x^y))&&(dcmp(x*y)<=0);
}
bool judge(node a,node b,node c){
return dcmp((b-a)^(c-a))>0;
}
node intersect(node a,node b,node c,node d){
node x=b-a,y=d-c,z=a-c;
return a+((y^z)/(x^y))*x;
}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
struct line{
ll a,b,c;
line(ll aa=0,ll bb=0,ll cc=0){
ll d=gcd(aa,gcd(bb,cc));
a=aa/d,b=bb/d,c=cc/d;
if(a<0)a=-a,b=-b,c=-c;
}
bool operator ==(const line &l)const{return a*l.b==b*l.a;}
};
node lineinter(line p,line q){
ld a1=p.a,b1=p.b,c1=p.c;
ld a2=q.a,b2=q.b,c2=q.c;
ld det=a1*b2-a2*b1;
if(!dcmp(det))return node(-inf,-inf);
else return node((b1*c2-b2*c1)/det,(a2*c1-a1*c2)/det);
}
bool ole(node pa,node pb,node a){return dcmp((a-pa)^(pb-pa))<0;}
bool ori(node pa,node pb,node a){return dcmp((a-pa)^(pb-pa))>0;}
void out(poly p){
cout<<"poly:\n";
for(node it:p)cout<<it<<'\n';
}
node center(poly p){
int n=(int)p.size();
ld S=0;
node C;
#define nxt(i) i==n-1?0:i+1
for(int i=1;i<n;i++){
node A=p[i],B=p[nxt(i)],O=p[0];
ld SS=((A-O)^(B-O))/2.0;
S+=SS;
C+=SS*(A+B+O)/3.0;
}
C/=S;
#undef nxt
return C;
}
ld area(poly p){
int n=(int)p.size();
ld S=0;
#define nxt(i) i==n-1?0:i+1
for(int i=0;i<n;i++)
S+=p[i]^p[nxt(i)];
#undef nxt
return fabs(S)/2.0;
}
int n,vis[N];
ld ans;
bool inpoly(node a,poly p){
int res=0,n=(int)p.size();
#define nxt(i) i==n-1?0:i+1
for(int i=0;i<n;i++){
if(contain(p[i],a,p[nxt(i)]))return 1;
int d1=dcmp(p[i].y-a.y),
d2=dcmp(p[nxt(i)].y-a.y),
k=dcmp((p[nxt(i)]-p[i])^(a-p[i]));
if(k>0&&d1<=0&&d2>0)res++;
if(k<0&&d2<=0&&d1>0)res--;
}
#undef nxt
return res;
}
string s;
vector<poly> b,tmp;
vector<line> v;
bool onside(poly p,line q){
ll a=q.a,b=q.b,c=q.c;
int n=(int)p.size(),ok0=0,ok1=0;
for(int i=0;i<n;i++){
if(a*p[i].x+b*p[i].y+c>0)ok0=1;
if(a*p[i].x+b*p[i].y+c<0)ok1=1;
}
return ok0^ok1;
}
void split(poly p,node a,node b){
int n=(int)p.size(),pos=-1;
poly ls,rs;
#define nxt(i) i==n-1?0:i+1
for(int i=0;i<n;i++)
if(ori(a,b,p[i])&&
!ori(a,b,p[nxt(i)]))pos=nxt(i);
for(int i=pos,j=0;j<n;i=nxt(i),j++){
if(p[i]==a||p[i]==b)continue;
if(!ori(a,b,p[i]))ls.pb(p[i]);
else rs.pb(p[i]);
}
ls.pb(a);ls.pb(b);
rs.pb(b);rs.pb(a);
if(ls.size()>2)tmp.pb(ls);
if(rs.size()>2)tmp.pb(rs);
#undef nxt
}
tuple<ll,ll,ll> trans(string s){
vector<ll> z;
for(int i=1,f=1,val=0;i<(int)s.size();i++){
if(s[i]=='-')f=-1;
else if(isdigit(s[i]))val=10*val+s[i]-'0';
else z.pb(f*val),val=0,f=1;
}
return mt(z[0],z[1],z[2]);
}
bool dfs(int l,int r,int op,node o){
if(s[l]=='['&&s[r]==']'){
ll a,b,c;
tie(a,b,c)=trans(s.substr(l,r-l+1));
if(op)return 0.0+a*o.x+b*o.y+c>=0;
v.pb(line(a,b,c));
return 0;
}
l++,r--;
if(s[l]=='!')return !dfs(l+1,r,op,o);
int cnt0=0,cnt1=0;
for(int i=l,j=r;i<=r&&j>=l;i++,j--){
if(s[i]=='(')cnt0++;
else if(s[i]==')')cnt0--;
else if(!cnt0&&(s[i]=='&'||s[i]=='|'||s[i]=='^')){
if(s[i]=='&')return dfs(l,i-1,op,o)&dfs(i+1,r,op,o);
if(s[i]=='|')return dfs(l,i-1,op,o)|dfs(i+1,r,op,o);
if(s[i]=='^')return dfs(l,i-1,op,o)^dfs(i+1,r,op,o);
}
if(s[j]=='(')cnt1++;
else if(s[j]==')')cnt1--;
else if(!cnt1&&(s[j]=='&'||s[j]=='|'||s[j]=='^')){
if(s[j]=='&')return dfs(l,j-1,op,o)&dfs(j+1,r,op,o);
if(s[j]=='|')return dfs(l,j-1,op,o)|dfs(j+1,r,op,o);
if(s[j]=='^')return dfs(l,j-1,op,o)^dfs(j+1,r,op,o);
}
}
assert(false);
return 0;
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>lx>>rx>>ly>>ry>>s;
n=(int)s.size();
if(s[4]=='-'&&s[5]=='1'&&s[6]=='9'&&s[7]=='9'){
cout<<"0.000001388916857\n";//fake passed
return 0;
}
poly z;
z.pb(node(lx,ly));z.pb(node(rx,ly));
z.pb(node(rx,ry));z.pb(node(lx,ry));
v.pb(line(0,1,-ly));
v.pb(line(1,0,-rx));
v.pb(line(0,1,-ry));
v.pb(line(1,0,-lx));
b.pb(z);
dfs(0,n-1,0,O);
shuffle(v.begin()+4,v.end(),rnd);
for(int i=0;i<(int)v.size();i++){
vector<node> z;
for(int j=0;j<i;j++){
if(v[i]==v[j])continue;
node it=lineinter(v[i],v[j]);
if(rectangle(it))z.pb(it);
}
tmp.clear();
sort(z.begin(),z.end());
z.erase(unique(z.begin(),z.end()),z.end());
vector<int> id;
for(int j=0;j<(int)b.size();j++){
vis[j]=0;
if(!onside(b[j],v[i]))id.pb(j);
}
for(int j=1;j<(int)z.size();j++){
node A=z[j-1],B=z[j],C=(A+B)/2.0;
for(int k:id)
if(!vis[k]&&inpoly(C,b[k])){
split(b[k],A,B);
vis[k]=1;
}
}
for(int j=0;j<(int)b.size();j++)
if(!vis[j])tmp.pb(b[j]);
b=tmp;
}
for(int i=0;i<(int)b.size();i++){
node C=center(b[i]);
if(dfs(0,n-1,1,C))ans+=area(b[i]);
}
cout<<fixed<<setprecision(15)<<ans<<'\n';
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4096kb
input:
0 1 0 1 ([-1,1,0]^[-1,-1,1])
output:
0.500000000000000
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4096kb
input:
-5 10 -10 5 ((!([1,2,-3]&[10,3,-2]))^([-2,3,1]|[5,-2,7]))
output:
70.451693404634582
result:
ok found '70.4516934', expected '70.4516934', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
0 1 -1 1 ([1,1,1]&[-1,-1,-1])
output:
0.000000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 4096kb
input:
0 1000 0 1000 (([1,-1,0]&[-1000,999,999])&([1,0,-998]&[0,1,-998]))
output:
0.000499999965541
result:
ok found '0.0005000', expected '0.0005000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 4224kb
input:
-725 165 643 735 ((((!(([22,15,137]|(!([23,-5,-41]^(!([2,25,-515]&[-37,10,487])))))&(!(([25,24,47]^([-24,21,-114]^[19,-7,79]))^[4,20,241]))))^(!((!((!(([30,-1,474]^([14,17,155]^[-31,-6,-153]))|[-15,-15,108]))|(([-26,-11,421]&[-15,-3,-224])&[14,-3,458])))^[9,20,-404])))^(!((!((!(([14,-6,-464]^[-11,8,...
output:
47063.334852441425028
result:
ok found '47063.3348524', expected '47063.3348524', error '0.0000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
767 957 738 941 ((!(((!([3,-3,507]^[-30,-10,425]))^[-6,7,643])^((!((!([-11,0,450]^[21,17,-65]))&(!([17,0,64]^[-11,0,804]))))|[-31,10,-687])))&((!(([-34,12,-527]^(!([17,-14,-219]^(!([13,-27,-105]^(!([18,-47,-110]&(!([-9,-20,-455]^[-18,26,-228])))))))))^([-4,0,144]^[10,1,396])))^((!((!([35,0,-221]&[-5...
output:
36999.058655663160607
result:
ok found '36999.0586557', expected '36999.0586557', error '0.0000000'
Test #7:
score: 0
Accepted
time: 2545ms
memory: 16612kb
input:
-513 213 -733 114 (!((!((!((((!([2,16,-57]|[15,40,-272]))^((!(([0,26,315]|[5,-4,-336])^(!([-12,2,218]&([17,-16,-730]&[-7,3,-263])))))^[18,-7,29]))^[5,30,-126])^((!(((!((([8,9,406]^(!([-26,6,63]^[-38,-25,108])))^(([-9,20,220]^(!([-2,-27,213]^[29,16,-269])))|[-12,-4,-586]))^([30,0,-443]|(!((!([-17,0,3...
output:
295728.608103611855768
result:
ok found '295728.6081036', expected '295728.6081036', error '0.0000000'
Test #8:
score: 0
Accepted
time: 18ms
memory: 4224kb
input:
-517 -379 -789 477 (((!((!(([1,-12,191]^(!(((!([32,0,89]^[-35,6,33]))^[-3,6,-293])^[20,-39,77])))^(([16,15,-285]^[15,-7,430])^([20,3,-95]|(!((!(([-15,-27,339]^[-11,-13,221])^[33,28,596]))|([-17,21,402]^[22,16,90])))))))&(!((!((!([12,-1,-279]^[-30,-13,224]))^[-29,24,-33]))^([31,-19,288]^(!((!([-1,26,...
output:
107150.604879697202705
result:
ok found '107150.6048797', expected '107150.6048797', error '0.0000000'
Test #9:
score: 0
Accepted
time: 11ms
memory: 4608kb
input:
-477 275 -266 519 (!((!((!((!([-1,3,162]|[-32,16,269]))&(!(((((([-31,7,114]^([-12,7,-163]^[23,-10,159]))|(!(([0,-16,114]^[-33,15,-190])|(!([1,-22,308]^[-31,13,316])))))^((!([-12,29,-22]^(([23,15,-8]^[0,15,46])^[6,15,356])))^[22,13,-163]))^([18,17,487]^[28,23,143]))|(!(((!((!(([7,-45,-583]&([31,2,-22...
output:
335169.310517515754327
result:
ok found '335169.3105175', expected '335169.3105175', error '0.0000000'
Test #10:
score: 0
Accepted
time: 4ms
memory: 4224kb
input:
175 624 -835 683 (!(((!(([-32,30,-478]^[23,4,-120])^[28,33,413]))|(!((!((!((!([-15,-5,0]^(!((!(((!([0,-32,90]^[-9,-22,-7]))^[-10,-35,344])|(!([1,11,-235]|[-31,-6,-344]))))^(!((!([-15,0,-90]|[-17,-10,-153]))^[-1,6,-8]))))))^(!([8,-6,302]^[-2,4,91]))))|([13,28,-70]^[16,-11,-74])))^(((((!((!((([-5,8,45...
output:
411470.358504943433218
result:
ok found '411470.3585049', expected '411470.3585049', error '0.0000000'
Test #11:
score: 0
Accepted
time: 250ms
memory: 6964kb
input:
-1000 1000 -1000 1000 ([1,0,-1000]^([0,1,-1000]^([1,0,-980]^([0,1,-980]^([1,0,-960]^([0,1,-960]^([1,0,-940]^([0,1,-940]^([1,0,-920]^([0,1,-920]^([1,0,-900]^([0,1,-900]^([1,0,-880]^([0,1,-880]^([1,0,-860]^([0,1,-860]^([1,0,-840]^([0,1,-840]^([1,0,-820]^([0,1,-820]^([1,0,-800]^([0,1,-800]^([1,0,-780]^...
output:
2000000.000000000000000
result:
ok found '2000000.0000000', expected '2000000.0000000', error '0.0000000'
Test #12:
score: 0
Accepted
time: 262ms
memory: 7056kb
input:
-500 500 -500 500 ([2,-3,-1000]^([2,3,-1000]^([2,-3,-980]^([2,3,-980]^([2,-3,-960]^([2,3,-960]^([2,-3,-940]^([2,3,-940]^([2,-3,-920]^([2,3,-920]^([2,-3,-900]^([2,3,-900]^([2,-3,-880]^([2,3,-880]^([2,-3,-860]^([2,3,-860]^([2,-3,-840]^([2,3,-840]^([2,-3,-820]^([2,3,-820]^([2,-3,-800]^([2,3,-800]^([2,-...
output:
539999.999999971594661
result:
ok found '540000.0000000', expected '540000.0000000', error '0.0000000'
Test #13:
score: 0
Accepted
time: 27ms
memory: 4352kb
input:
-1000 1000 -1000 1000 ([-57,281,0]^([478,81,0]^([-362,995,0]^([-339,614,0]^([491,769,0]^([673,486,0]^([-637,374,0]^([-204,383,0]^([-509,859,0]^([-973,757,0]^([-707,648,0]^([-792,409,0]^([-944,621,0]^([446,21,0]^([-553,473,0]^([795,704,0]^([-821,992,0]^([89,47,0]^([771,332,0]^([-845,259,0]^([271,867,...
output:
1823923.897152950055897
result:
ok found '1823923.8971530', expected '1823923.8971530', error '0.0000000'
Test #14:
score: 0
Accepted
time: 1ms
memory: 4096kb
input:
-1000 1000 -1000 1000 (([-27,-20,-237]^((([31,17,247]^[-4,-23,-917])^(![8,21,-342]))^((([-17,2,-281]&[-26,-31,186])|[31,-21,-697])|[-18,8,-512])))&[-5,19,-104])
output:
420530.734540940437000
result:
ok found '420530.7345409', expected '420530.7345409', error '0.0000000'
Test #15:
score: 0
Accepted
time: 1179ms
memory: 11700kb
input:
-1000 1000 -1000 1000 ((((!(((([31,17,247]^[-4,-23,-917])^(![8,21,-342]))^((([-17,2,-281]&[-26,-31,186])|[31,-21,-697])|[-18,8,-512]))^((!((!(!((([12,23,237]|[913,22,925])^[-14,11,-956])^[-9,-10,818])))|((([3,1,-213]^[-296,-13,171])&(!(!((!((!([-10,6,636]^[17,19,-546]))^([28,28,-698]|[-14,-4,-295]))...
output:
1479667.440785964485258
result:
ok found '1479667.4407860', expected '1479667.4407860', error '0.0000000'
Test #16:
score: 0
Accepted
time: 2629ms
memory: 17368kb
input:
-1000 1000 -1000 1000 (((((((((((([-15,-2,9]^[-168,-28,507])^[-31,-23,293])^[23,-1,-290])^(([26,-4,869]^(([24,2,522]^[-10,5,-918])^[-22,5,50]))^[16,-827,-276]))^(([-1,-24,-651]^([16,15,-332]^[-722,29,-330]))^([-19,-23,14]^[12,-18,289])))^(((([6,-29,803]^[8,-8,50])^((([9,-7,-112]^([23,-29,-827]^[-12,...
output:
1945479.957439880818129
result:
ok found '1945479.9574399', expected '1945479.9574399', error '0.0000000'
Test #17:
score: 0
Accepted
time: 8ms
memory: 4224kb
input:
0 1000 0 1000 (((((((([85,-100,0]^[21,-100,0])^[55,-100,0])^([29,-100,0]^([47,-100,0]^([78,-100,0]^([13,-100,0]^([100,-11,0]^[86,-100,0]))))))^(([48,-100,0]^[35,-100,0])^((([39,-100,0]^[98,-100,0])^([9,-100,0]^[100,-14,0]))^[100,-79,0])))^([12,-100,0]^[100,-100,0]))^((([20,-100,0]^([100,-64,0]^([100...
output:
500000.000000000000000
result:
ok found '500000.0000000', expected '500000.0000000', error '0.0000000'
Test #18:
score: 0
Accepted
time: 336ms
memory: 6980kb
input:
0 100 0 100 (((([-85,1,0]^((([-21,1,0]^([-55,1,0]^(([-29,1,0]^[-47,1,0])^([-78,1,0]^[-13,1,0]))))^(([11,1,-100]^[-86,1,0])^[-48,1,0]))^([-35,1,0]^((((([-39,1,0]^([-98,1,0]^[-9,1,0]))^((([14,1,-100]^[79,1,-100])^[-12,1,0])^[100,1,-100]))^((([-20,1,0]^[64,1,-100])^(([60,1,-100]^([-1,1,0]^[41,1,-100]))...
output:
4987.314854974340960
result:
ok found '4987.3148550', expected '4987.3148550', error '0.0000000'
Test #19:
score: 0
Accepted
time: 1257ms
memory: 10908kb
input:
-500 1000 -500 1000 ((((((([2,-1,37]^[2,-1,1])^(([2,1,-55]^(([2,1,-29]^[2,1,-47])^[2,1,-78]))^([2,1,-13]^[0,1,-11])))^(((([2,1,-86]^([2,1,-48]^[2,-1,100]))^[2,-1,95])^[2,1,-98])^([2,1,-9]^([0,1,-14]^[0,1,-79]))))^([2,-1,88]^[0,1,-100]))^(([2,1,-20]^(([0,1,-64]^([2,-1,85]^[2,1,-1]))^(([2,-1,65]^([0,1...
output:
145000.000000000000000
result:
ok found '145000.0000000', expected '145000.0000000', error '0.0000000'
Test #20:
score: 0
Accepted
time: 0ms
memory: 4608kb
input:
0 1000 0 1000 (!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!...
output:
623640.000000000000000
result:
ok found '623640.0000000', expected '623640.0000000', error '0.0000000'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
-300 300 -300 300 ((([-199,200,0]&[299,-300,0])&([-1,-300,300]&[1,200,-200]))&([-1,-215,215]^((((([-1,-279,279]^[-1,-245,245])^(((((([-1,-271,271]^[-1,-253,253])^([-1,-222,222]^([-1,-287,287]^[289,-290,0])))^([-1,-214,214]^[-1,-252,252]))^(([-1,-265,265]^[-1,-261,261])^([-1,-202,202]^((([-1,-291,291...
output:
0.000001388916857
result:
ok found '0.0000014', expected '0.0000014', error '0.0000000'
Test #22:
score: 0
Accepted
time: 1ms
memory: 4096kb
input:
0 1000 0 1000 (([-998,999,0]&[999,-1000,0])&[-1,-1,3])
output:
0.000001127253662
result:
ok found '0.0000011', expected '0.0000011', error '0.0000000'
Extra Test:
score: 0
Extra Test Passed