QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#328761 | #7862. Land Trade | ucup-team134 | RE | 1ms | 3900kb | C++17 | 5.3kb | 2024-02-16 06:10:01 | 2024-02-16 06:10:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ldb double
#define ll long long
#define pb push_back
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 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;
}
const ldb eps=1e-9;
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;
}
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();
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,g});
}
}
if(sec.size()<2){
newPolys.pb(poly);
}else if(sec.size()==2){
int l=sec[0].first;
int r=sec[1].first;
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]);
}
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]);
}
B.pb(sec[0].second);
newPolys.pb(Clean(B));
}else{
printf("%i\n",sec.size());
for(pt p:poly)printf("(%.2lf, %.2lf)\n",p.x,p.y);
for(int i=0;i<sec.size();i++)printf("%i %.2lf %.2lf\n",sec[i].first,sec[i].second.x,sec[i].second.y);
assert(false);
}
}
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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3804kb
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: 0ms
memory: 3792kb
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: 0ms
memory: 3844kb
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: 0ms
memory: 3856kb
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: 0ms
memory: 3900kb
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: 0ms
memory: 3840kb
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: -100
Runtime Error
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...