QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#269092 | #7862. Land Trade | ucup-team1209# | RE | 1ms | 4388kb | C++20 | 3.5kb | 2023-11-29 12:20:39 | 2023-11-29 12:20:40 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin, std::cout;
using ll = long long;
using db = long double;
struct vec2 { db x, y; };
const db eps = 1e-9;
db sgn(db x) {
return x < -eps ? -1 : x > eps;
}
vec2 operator + (vec2 x, vec2 y) { return {x.x + y.x, x.y + y.y}; }
vec2 operator - (vec2 x, vec2 y) { return {x.x - y.x, x.y - y.y}; }
vec2 operator / (vec2 x, db y) { return {x.x / y, x.y / y}; }
db operator * (vec2 x, vec2 y) { return x.x * y.y - x.y * y.x; }
vec2 r90(vec2 x) {
return {-x.y, x.x};
}
struct line : vec2 {
db z;
line() {}
line(vec2 x, vec2 y) : vec2{r90(y - x)}, z(x * y) {
}
line flip() const {
return line(-x, -y, -z);
}
line(db a, db b, db c) : vec2{a, b}, z(c) {}
db operator () (vec2 a) const { return a.x * x + a.y * y + z; }
};
vec2 operator & (line x, line y) {
return vec2{vec2{x.z, x.y} * vec2{y.z, y.y}, vec2{x.x, x.z} * vec2{y.x, y.z}} / -(vec2(x) * vec2(y));
}
std::vector<vec2> cut(const std::vector<vec2> & o, line l) {
std::vector<vec2> res;
int n = size(o);
for(int i = 0;i < n;++i) {
vec2 a = o[i], b = o[(i + 1) % o.size()];
if(sgn(l(a)) >= 0) res.push_back(a);
if(sgn(l(a)) * sgn(l(b)) < 0) res.push_back(line(a, b) & l);
}
return res;
}
std::vector<std::vector<vec2>> convs, tmp;
const int N = 300;
const int M = N * N + 5;
line a[N];
int cnt;
int cc;
vec2 o[N];
vec2 x, y;
char s[1 << 20];
void solve(int & id) {
if(s[id] == '(') {
++ id;
if(s[id] == '!') {
solve(++id);
} else {
solve(id);
solve(++id);
}
++id;
} else {
std::vector<std::string> ts;
std::string t;
for(;s[++id] != ']';) {
if(s[id] == ',') {
ts.push_back(t), t = "";
} else {
t += s[id];
}
}
ts.push_back(t);
a[cnt++] = line(atof(ts[0].c_str()), atof(ts[1].c_str()), atof(ts[2].c_str()));
++id;
}
}
std::bitset<M> solve1(int & id) {
if(s[id] == '(') {
++ id;
if(s[id] == '!') {
auto t = solve1(++id);
++ id;
return ~t;
} else {
auto le = solve1(id);
char op = s[id];
auto ri = solve1(++id);
++id;
if(op == '&') return le & ri;
if(op == '|') return le | ri;
if(op == '^') return le ^ ri;
assert(0);
}
} else {
std::vector<std::string> ts;
std::string t;
for(;s[++id] != ']';) {
if(s[id] == ',') {
ts.push_back(t), t = "";
} else {
t += s[id];
}
}
ts.push_back(t);
line z = line(atof(ts[0].c_str()), atof(ts[1].c_str()), atof(ts[2].c_str()));
++id;
std::bitset<M> res;
for(int i = 0;i < cc;++i) {
if(sgn(z(o[i])) == 1) res.set(i);
}
return res;
}
}
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
cin >> x.x >> y.x;
cin >> x.y >> y.y;
convs.push_back({ {x.x, x.y}, {y.x, x.y}, {y.x, y.y}, {x.x, y.y} });
cin >> s;
int id = 0;
solve(id);
for(int i = 0;i < cnt;++i) {
tmp = convs, convs.clear();
for(auto x : tmp) {
db min = 1e9, max = -1e9;
for(vec2 t : x) {
min = std::min(min, a[i](t));
max = std::max(max, a[i](t));
}
if(sgn(max) == 1) {
convs.push_back(cut(x, a[i]));
}
if(sgn(min) == -1) {
convs.push_back(cut(x, a[i].flip()));
}
}
}
cc = size(convs);
for(int i = 0;i < cc;++i) {
for(vec2 x : convs[i]) o[i] = o[i] + x;
o[i] = o[i] / db(convs[i].size());
}
id = 0;
auto t = solve1(id);
db ans = 0;
for(int i = 0;i < cc;++i) if(t.test(i)) {
db sum = 0;
auto z = convs[i];
for(int j = 2;j < z.size();++j) {
sum += (z[j - 1] - z[0]) * (z[j] - z[0]);
}
ans += sum;
}
printf("%.10Lf\n", ans / 2);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
input:
0 1 0 1 ([-1,1,0]^[-1,-1,1])
output:
0.5000000000
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3740kb
input:
-5 10 -10 5 ((!([1,2,-3]&[10,3,-2]))^([-2,3,1]|[5,-2,7]))
output:
70.4516934046
result:
ok found '70.4516934', expected '70.4516934', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
0 1 -1 1 ([1,1,1]&[-1,-1,-1])
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3856kb
input:
0 1000 0 1000 (([1,-1,0]&[-1000,999,999])&([1,0,-998]&[0,1,-998]))
output:
0.0005000000
result:
ok found '0.0005000', expected '0.0005000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 4388kb
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.3348524415
result:
ok found '47063.3348524', expected '47063.3348524', error '0.0000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 4216kb
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.0586556632
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...