QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328773#7862. Land Tradeucup-team134AC ✓1198ms16940kbC++175.6kb2024-02-16 06:22:042024-02-16 06:22:04

Judging History

你现在查看的是最新测评结果

  • [2024-02-16 06:22:04]
  • 评测
  • 测评结果:AC
  • 用时:1198ms
  • 内存:16940kb
  • [2024-02-16 06:22:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ldb double
#define ll long long
#define pb push_back

const ldb eps=1e-9;

struct pt{
	ldb x,y;
	pt():x(0),y(0){}
	pt(ldb a,ldb b):x(a),y(b){}
};

pt operator + (pt a,pt b){return pt(a.x+b.x,a.y+b.y);}
pt operator - (pt a,pt b){return pt(a.x-b.x,a.y-b.y);}
pt operator * (pt a,ldb b){return pt(a.x*b,a.y*b);}
pt operator / (pt a,ldb b){return pt(a.x/b,a.y/b);}

ldb dot(pt a,pt b){return a.x*b.x+a.y*b.y;}
ldb cross(pt a,pt b){return a.x*b.y-a.y*b.x;}

struct line{
	pt v;
	ldb c;

	line(pt a,pt b){
		v=b-a;
		c=cross(v,a);
	}

	line(ldb a,ldb b,ldb _c){
		v=pt(b,-a);
		c=-_c;
	}

	bool in_order(pt P, pt Q, pt R){
		ldb p=dot(P,v);
		ldb q=dot(Q,v);
		ldb r=dot(R,v);
		return p<=q && q<=r;
	}

	bool is_on(pt P){
		return abs(cross(v,P)-c)<eps;
	}
};

bool paralel(line a,line b){
	return cross(a.v,b.v)==0;
}

pt inter(line a,line b){
	pt ans=(a.v*b.c-b.v*a.c)/cross(b.v,a.v);
	return ans;
}

struct expr{
	virtual bool check(pt p) = 0;
};

struct func : public expr{
	ll a,b,c;

	func(ll x,ll y,ll z):a(x),b(y),c(z){}

	ldb eval(pt p){
		return a*p.x+b*p.y+c;
	}

	bool check(pt p) override {
		return eval(p)>=0;
	}
};

struct op : public expr{
	char o;
	expr* l;
	expr* r;

	op(char _o, expr* _l, expr* _r=nullptr):o(_o),l(_l),r(_r){}

	bool check(pt p) override {
		if(o=='!')return !l->check(p);
		else if(o=='&')return l->check(p) && r->check(p);
		else if(o=='|')return l->check(p) || r->check(p);
		else if(o=='^')return l->check(p) ^ r->check(p);
		return false;
	}
};

string s;

int Find(int from,char c){
	while(s[from]!=c)from++;
	return from;
}

vector<line> lines;

expr* Parse(int l,int r){
	if(s[l]=='['){
		int ptr=Find(l+1,',');
		ll a=stoi(s.substr(l+1,ptr-l-1));
		l=ptr;
		ptr=Find(l+1,',');
		ll b=stoi(s.substr(l+1,ptr-l-1));
		l=ptr;
		ptr=Find(l+1,']');
		ll c=stoi(s.substr(l+1,ptr-l-1));
		lines.pb(line(a,b,c));
		return new func(a,b,c);
	}
	int bal=0;
	for(int i=l;i<=r;i++){
		if(s[i]=='(')bal++;
		if(s[i]==')')bal--;
		if(bal==1 && (s[i]=='!' || s[i]=='^' || s[i]=='&' || s[i]=='|')){
			if(s[i]=='!'){
				return new op(s[i], Parse(i+1,r-1));
			}else{
				return new op(s[i], Parse(l+1,i-1), Parse(i+1,r-1));
			}
		}
	}
}

ldb area(pt a,pt b,pt c){
	ldb ans=cross(a,b)+cross(b,c)+cross(c,a);
	return abs(ans)/2;
}

ldb area(vector<pt> poly){
	ldb ans=0;
	for(int i=0;i<poly.size();i++){
		int j=(i+1)%poly.size();
		ans+=cross(poly[i],poly[j]);
	}
	return abs(ans)/2;
}

pt GetCentroid(vector<pt> poly){
	pt ans(0,0);
	ldb q=0;
	for(int i=0;i<poly.size();i++){
		int j=(i+1)%poly.size();
		ldb cr=cross(poly[i],poly[j]);
		ans=ans+(poly[i]+poly[j])/3*cr;
		q+=cr;
	}
	return ans/q;
}

vector<pt> Clean(vector<pt> poly){
	/*vector<pt> ans;
	for(int i=0;i<poly.size();i++){
		int j=(i+1)%poly.size();
		pt diff=poly[i]-poly[j];
		if(abs(diff.x)<eps && abs(diff.y)<eps){
			continue;
		}
		ans.pb(poly[i]);
	}
	return ans;*/
	return poly;
}

vector<vector<pt>> newPolys;
void Split(vector<pt> poly, line a){
	vector<pair<int,pt>> sec;
	for(int i=0;i<poly.size();i++){
		int j=(i+1)%poly.size();

		if(a.is_on(poly[i])){
			sec.pb({-(i+1),poly[i]});
		}
		if(a.is_on(poly[i]) || a.is_on(poly[j]))continue;

		line b=line(poly[i],poly[j]);
		if(paralel(a,b))continue;
		pt g=inter(a,b);
		if(b.in_order(poly[i],g,poly[j])){
			sec.pb({i+1,g});
		}
	}
	if(sec.size()<2){
		newPolys.pb(poly);
	}else if(sec.size()==2){
		int l=abs(sec[0].first)-1;
		int r=abs(sec[1].first)-1;
		vector<pt> A;
		A.pb(sec[0].second);
		for(int i=(l+1)%poly.size();i!=(r+1)%poly.size();i=(i+1)%poly.size()){
			A.pb(poly[i]);
		}
		if(sec[1].first<0)A.pop_back();
		A.pb(sec[1].second);
		newPolys.pb(Clean(A));
		vector<pt> B;
		B.pb(sec[1].second);
		for(int i=(r+1)%poly.size();i!=(l+1)%poly.size();i=(i+1)%poly.size()){
			B.pb(poly[i]);
		}
		if(sec[0].first<0)B.pop_back();
		B.pb(sec[0].second);
		newPolys.pb(Clean(B));
	}else{
		printf("%i\n",sec.size());
		for(int i=0;i<sec.size();i++)printf("%i %.2lf %.2lf\n",sec[i].first,sec[i].second.x,sec[i].second.y);
		for(pt p:poly)printf("(%.2lf, %.2lf)\n",p.x,p.y);
		exit(0);
	}
}

int main(){
	int xl,xr,yl,yr;
	scanf("%i %i %i %i",&xl,&xr,&yl,&yr);
	cin>>s;
	expr* e=Parse(0,s.size()-1);
	//lines.pb(line(pt(xl,yl),pt(xl,yr)));
	//lines.pb(line(pt(xl,yl),pt(xr,yl)));
	//lines.pb(line(pt(xr,yr),pt(xl,yr)));
	//lines.pb(line(pt(xr,yr),pt(xr,yl)));

	vector<vector<pt>> polys={{
		pt(xl,yl),
		pt(xl,yr),
		pt(xr,yr),
		pt(xr,yl)
	}};

	for(line a:lines){
		newPolys.clear();
		for(vector<pt> poly:polys){
			Split(poly, a);
		}
		polys=newPolys;
		/*printf("Polys:\n");
		for(vector<pt> poly:polys){
			for(pt p:poly)printf("(%.2lf %.2lf) ",p.x,p.y);
			printf("\n");
		}*/
	}

	/*vector<pt> pts;
	for(line a:lines){
		for(line b:lines){
			if(!paralel(a,b)){
				pts.pb(inter(a,b));
			}
		}
	}*/

	ldb ans=0;

	ldb totalArea=0;
	for(vector<pt> poly: polys){
		pt cen=GetCentroid(poly);
		//printf("Cen (%.2lf, %.2lf) %.2lf\n",cen.x,cen.y,area(poly));
		//totalArea+=area(poly);
		if(e->check(cen)){
			//printf("Take\n");
			ans+=area(poly);
		}
	}

	//printf("total area: %.2lf (%i)\n",totalArea,(xr-xl)*(yr-yl));
	/*vector<array<pt,3>> triangles=Triangulate(pts);
	for(auto tr:triangles){
		pt cen=(tr[0]+tr[1]+tr[2])/3;
		if(cen.x>=xl && cen.x<=xr && cen.y>=yl && cen.y<=yr){
			if(e->check(cen)){
				ans+=area(tr[0],tr[1],tr[2]);
			}
		}
	}*/

	cout << fixed << setprecision(12) << ans << std::endl;

	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3884kb

input:

0 1 0 1
([-1,1,0]^[-1,-1,1])

output:

0.500000000000

result:

ok found '0.5000000', expected '0.5000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

-5 10 -10 5
((!([1,2,-3]&[10,3,-2]))^([-2,3,1]|[5,-2,7]))

output:

70.451693404635

result:

ok found '70.4516934', expected '70.4516934', error '0.0000000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 4064kb

input:

0 1 -1 1
([1,1,1]&[-1,-1,-1])

output:

0.000000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

0 1000 0 1000
(([1,-1,0]&[-1000,999,999])&([1,0,-998]&[0,1,-998]))

output:

0.000499999966

result:

ok found '0.0005000', expected '0.0005000', error '0.0000000'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3912kb

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.334852441360

result:

ok found '47063.3348524', expected '47063.3348524', error '0.0000000'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3924kb

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.058655663161

result:

ok found '36999.0586557', expected '36999.0586557', error '0.0000000'

Test #7:

score: 0
Accepted
time: 1150ms
memory: 16272kb

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.608103598643

result:

ok found '295728.6081036', expected '295728.6081036', error '0.0000000'

Test #8:

score: 0
Accepted
time: 7ms
memory: 4068kb

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.604879697130

result:

ok found '107150.6048797', expected '107150.6048797', error '0.0000000'

Test #9:

score: 0
Accepted
time: 5ms
memory: 4456kb

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.310517515929

result:

ok found '335169.3105175', expected '335169.3105175', error '0.0000000'

Test #10:

score: 0
Accepted
time: 2ms
memory: 3908kb

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.358504943375

result:

ok found '411470.3585049', expected '411470.3585049', error '0.0000000'

Test #11:

score: 0
Accepted
time: 103ms
memory: 6612kb

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.000000000000

result:

ok found '2000000.0000000', expected '2000000.0000000', error '0.0000000'

Test #12:

score: 0
Accepted
time: 118ms
memory: 6880kb

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.999999967287

result:

ok found '540000.0000000', expected '540000.0000000', error '0.0000000'

Test #13:

score: 0
Accepted
time: 13ms
memory: 4308kb

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.897152948892

result:

ok found '1823923.8971529', expected '1823923.8971530', error '0.0000000'

Test #14:

score: 0
Accepted
time: 1ms
memory: 4076kb

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.734540940321

result:

ok found '420530.7345409', expected '420530.7345409', error '0.0000000'

Test #15:

score: 0
Accepted
time: 426ms
memory: 11524kb

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.440785964020

result:

ok found '1479667.4407860', expected '1479667.4407860', error '0.0000000'

Test #16:

score: 0
Accepted
time: 1198ms
memory: 16940kb

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.957439879654

result:

ok found '1945479.9574399', expected '1945479.9574399', error '0.0000000'

Test #17:

score: 0
Accepted
time: 3ms
memory: 4136kb

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.000000000000

result:

ok found '500000.0000000', expected '500000.0000000', error '0.0000000'

Test #18:

score: 0
Accepted
time: 101ms
memory: 6588kb

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.314854974314

result:

ok found '4987.3148550', expected '4987.3148550', error '0.0000000'

Test #19:

score: 0
Accepted
time: 488ms
memory: 10612kb

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.000000000000

result:

ok found '145000.0000000', expected '145000.0000000', error '0.0000000'

Test #20:

score: 0
Accepted
time: 1ms
memory: 4520kb

input:

0 1000 0 1000
(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!...

output:

623640.000000000000

result:

ok found '623640.0000000', expected '623640.0000000', error '0.0000000'

Test #21:

score: 0
Accepted
time: 114ms
memory: 7080kb

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.000001388917

result:

ok found '0.0000014', expected '0.0000014', error '0.0000000'

Test #22:

score: 0
Accepted
time: 1ms
memory: 3924kb

input:

0 1000 0 1000
(([-998,999,0]&[999,-1000,0])&[-1,-1,3])

output:

0.000001127254

result:

ok found '0.0000011', expected '0.0000011', error '0.0000000'

Extra Test:

score: 0
Extra Test Passed