QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355483 | #7862. Land Trade | ucup-team1191# | AC ✓ | 580ms | 41416kb | C++20 | 10.0kb | 2024-03-16 18:22:59 | 2024-03-16 18:23:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)
// _________ vect (2D) ______________
template <typename T>
struct vect {
T x = 0;
T y = 0;
vect() = default;
vect(T x_, T y_) : x(x_), y(y_) {}
inline T len2() const {
return x * x + y * y;
}
inline ld len() const {
return sqrtl(len2());
}
inline vect rotate() const {
return vect(-y, x);
}
};
template <typename T>
inline istream& operator>>(istream& in, vect<T>& v) {
return in >> v.x >> v.y;
}
template <typename T>
inline ostream& operator<<(ostream& out, const vect<T>& v) {
return out << "[" << v.x << "," << v.y << "]";
}
template <typename T>
inline vect<T> operator+(const vect<T>& a, const vect<T>& b) {
return vect<T>(a.x + b.x, a.y + b.y);
}
template <typename T>
inline vect<T> operator-(const vect<T>& a, const vect<T>& b) {
return vect<T>(a.x - b.x, a.y - b.y);
}
template <typename T>
inline vect<T> operator*(const vect<T>& a, T k) {
return vect<T>(a.x * k, a.y * k);
}
template <typename T>
inline T operator*(const vect<T>& a, const vect<T>& b) {
return a.x * b.x + a.y * b.y;
}
template <typename T>
inline T operator^(const vect<T>& a, const vect<T>& b) {
return a.x * b.y - a.y * b.x;
}
// _________ line (2D) ______________
template <typename T>
struct line {
T a = 0;
T b = 0;
T c = 0;
line() = default;
line(T a_, T b_, T c_) : a(a_), b(b_), c(c_) {}
line(const vect<T>& p, const vect<T>& dir) : a(-dir.y), b(dir.x), c(-(dir ^ p)) {}
inline vect<T> normal() const {
return vect<T>(a, b);
}
inline T calc(const vect<T>& pt) const {
return a * pt.x + b * pt.y + c;
}
};
template <typename T>
inline istream& operator>>(istream& in, line<T>& l) {
return in >> l.a >> l.b >> l.c;
}
template <typename T>
inline ostream& operator<<(ostream& out, const line<T>& l) {
//return out << l.a << "*x+" << l.b << "*y+" << l.c << "=0";
return out << l.a << " " << l.b << " " << l.c;
}
template <typename T>
inline line<T> linePoints(const vect<T>& A, const vect<T>& B) {
return line<T>(A, B - A);
}
template <typename T>
vect<ld> intersection(const line<T>& l1, const line<T>& l2) {
auto pr = l1.a * l2.b - l1.b * l2.a;
assert(abs(pr) > 1e-10);
auto prx = l1.b * l2.c - l1.c * l2.b;
auto pry = l1.c * l2.a - l1.a * l2.c;
return vect<ld>((ld)prx / pr, (ld)pry / pr);
}
vector<line<ld>> lines;
struct Node {
Node* l, *r;
int tp; // -1 -> line ; 0 -> & ; 1 -> | ; 2 -> ^ ; 3 -> !
int idx;
Node(Node* l, Node* r, int tp, int idx) : l(l), r(r), tp(tp), idx(idx) {}
bool calculate(const vect<ld>& p) {
if (tp == -1) {
return lines[idx].calc(p) >= 0;
}
if (tp == 0) {
return l->calculate(p) && r->calculate(p);
}
if (tp == 1) {
return l->calculate(p) || r->calculate(p);
}
if (tp == 2) {
return l->calculate(p) ^ r->calculate(p);
}
if (tp == 3) {
return !l->calculate(p);
}
assert(false);
}
};
string s;
line<ld> find_line(int l, int r) {
vector<int> pos;
for (int i = l; i < r; i++) {
if (s[i] == ',') {
pos.emplace_back(i);
}
}
assert(pos.size() == 2);
line<ld> res;
res.a = stoi(s.substr(l + 1, pos[0] - l - 1));
res.b = stoi(s.substr(pos[0] + 1, pos[1] - pos[0] - 1));
res.c = stoi(s.substr(pos[1] + 1, r - pos[1] - 1));
return res;
}
Node* construct(int l, int r) {
//cerr << "go " << s.substr(l, r - l) << "\n";
if (s[l] == '[') {
auto line = find_line(l, r);
lines.emplace_back(line);
return new Node(nullptr, nullptr, -1, (int)lines.size() - 1);
}
assert(s[l] == '(' && s[r - 1] == ')');
if (s[l + 1] == '!') {
return new Node(
construct(l + 2, r - 1),
nullptr,
3,
-1
);
}
int bal = 0;
int p = -1;
for (int i = l + 1; i < r - 1; i++) {
if (s[i] == '(') {
bal++;
} else if (s[i] == ')') {
bal--;
}
if (bal == 0 && (s[i] == '&' || s[i] == '|' || s[i] == '^')) {
p = i;
break;
}
}
assert(p != -1);
int tp;
if (s[p] == '&') {
tp = 0;
} else if (s[p] == '|') {
tp = 1;
} else {
tp = 2;
}
return new Node(
construct(l + 1, p),
construct(p + 1, r - 1),
tp,
-1
);
}
const ld eps = 1e-8;
struct Polygon {
vector<vect<ld>> pt;
vector<line<ld>> lines;
Polygon(const vector<vect<ld>>& pt, const vector<line<ld>>& lines) : pt(pt), lines(lines) {}
bool is_sep(const line<ld>& line) const {
ld mx = -1e18;
ld mn = 1e18;
for (const auto& p : pt) {
auto val = line.calc(p);
mn = min(mn, val);
mx = max(mx, val);
}
if (mn >= -eps) {
return false;
}
if (mx <= eps) {
return false;
}
return true;
}
};
ostream& operator<<(ostream& out, const Polygon& poly) {
out << "Polygon\n";
for (const auto& p : poly.pt) {
out << p.x << " " << p.y << "\n";
}
out << "...";
return out;
}
Polygon get_rect(int xmin, int xmax, int ymin, int ymax) {
vector<vect<ld>> pt;
pt.emplace_back(xmin, ymin);
pt.emplace_back(xmax, ymin);
pt.emplace_back(xmax, ymax);
pt.emplace_back(xmin, ymax);
vector<line<ld>> ln;
ln.emplace_back(0.0, 1.0, -ymin);
ln.emplace_back(-1.0, 0.0, xmax);
ln.emplace_back(0.0, -1.0, ymax);
ln.emplace_back(1.0, 0.0, -xmin);
return Polygon(pt, ln);
}
void sep(const Polygon& poly, const line<ld>& line, vector<Polygon>& into) {
const auto& pt = poly.pt;
int n = pt.size();
vector<ld> vals(n);
for (int i = 0; i < n; i++) {
vals[i] = line.calc(pt[i]);
}
for (int i = 0; i < n; i++) {
if (abs(vals[i]) < eps || (vals[i] <= -eps && vals[(i + 1) % n] >= eps) || (vals[i] >= eps && vals[(i + 1) % n] <= -eps)) {
auto st = pt[i];
if (abs(vals[i]) >= eps) {
st = intersection(poly.lines[i], line);
}
int best = -1;
ld bd = -1e18;
for (int j = i + 1; j != i; j = (j + 1) % n) {
if (abs(vals[j]) < eps || (vals[j] <= -eps && vals[(j + 1) % n] >= eps) || (vals[j] >= eps && vals[(j + 1) % n] <= -eps)) {
ld cur = (pt[j] - st).len2();
if (cur > bd) {
best = j;
bd = cur;
}
}
}
assert(best != -1);
int j = best;
auto fn = pt[j];
if (abs(vals[j]) >= eps) {
fn = intersection(poly.lines[j], line);
}
{
vector<vect<ld>> now_pt;
vector<::line<ld>> now_lines;
now_pt.emplace_back(st);
now_lines.emplace_back(poly.lines[i]);
for (int x = i; x != j; x = (x + 1) % n) {
now_pt.emplace_back(pt[(x + 1) % n]);
now_lines.emplace_back(poly.lines[(x + 1) % n]);
}
now_pt.emplace_back(fn);
now_lines.emplace_back(line);
into.emplace_back(now_pt, now_lines);
}
{
vector<vect<ld>> now_pt;
vector<::line<ld>> now_lines;
swap(fn, st);
swap(i, j);
now_pt.emplace_back(st);
now_lines.emplace_back(poly.lines[i]);
for (int x = i; x != j; x = (x + 1) % n) {
now_pt.emplace_back(pt[(x + 1) % n]);
now_lines.emplace_back(poly.lines[(x + 1) % n]);
}
now_pt.emplace_back(fn);
now_lines.emplace_back(line);
into.emplace_back(now_pt, now_lines);
}
break;
}
}
}
void solve() {
int xmin, xmax, ymin, ymax;
cin >> xmin >> xmax >> ymin >> ymax;
cin >> s;
auto f = construct(0, s.size());
vector<Polygon> polygons;
polygons.emplace_back(get_rect(xmin, xmax, ymin, ymax));
for (const auto& line : lines) {
/*for (const auto& poly : polygons) {
cout << poly << "\n";
}
cout << string(100, '-') << "\n";*/
vector<Polygon> nw;
for (const auto& poly : polygons) {
if (poly.is_sep(line)) {
sep(poly, line, nw);
} else {
nw.emplace_back(poly);
}
}
swap(polygons, nw);
}
/*for (const auto& poly : polygons) {
cout << poly << "\n";
}*/
ld ans = 0.0;
for (const auto& poly : polygons) {
vect<ld> sm(0, 0);
for (const auto& p : poly.pt) {
sm = sm + p;
}
sm.x /= poly.pt.size();
sm.y /= poly.pt.size();
if (f->calculate(sm)) {
ld area = 0.0;
for (int i = 0; i < (int)poly.pt.size(); ++i) {
area += (poly.pt[i] ^ poly.pt[(i + 1) % (int)poly.pt.size()]);
}
ans += abs(area) / 2.0;
}
}
cout << ans << "\n";
}
int main() {
#ifdef ONPC
freopen("input", "r", stdin);
#endif
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3856kb
input:
0 1 0 1 ([-1,1,0]^[-1,-1,1])
output:
0.50000000000000000000
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3972kb
input:
-5 10 -10 5 ((!([1,2,-3]&[10,3,-2]))^([-2,3,1]|[5,-2,7]))
output:
70.45169340463458110269
result:
ok found '70.4516934', expected '70.4516934', error '0.0000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
0 1 -1 1 ([1,1,1]&[-1,-1,-1])
output:
0.00000000000000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
0 1000 0 1000 (([1,-1,0]&[-1000,999,999])&([1,0,-998]&[0,1,-998]))
output:
0.00050000000001659828
result:
ok found '0.0005000', expected '0.0005000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3976kb
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.33485244147654924518
result:
ok found '47063.3348524', expected '47063.3348524', error '0.0000000'
Test #6:
score: 0
Accepted
time: 1ms
memory: 4032kb
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.05865566322222548479
result:
ok found '36999.0586557', expected '36999.0586557', error '0.0000000'
Test #7:
score: 0
Accepted
time: 527ms
memory: 38700kb
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.60810361067740359431
result:
ok found '295728.6081036', expected '295728.6081036', error '0.0000000'
Test #8:
score: 0
Accepted
time: 6ms
memory: 4136kb
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.60487969717621581367
result:
ok found '107150.6048797', expected '107150.6048797', error '0.0000000'
Test #9:
score: 0
Accepted
time: 4ms
memory: 4728kb
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.31051751586571185726
result:
ok found '335169.3105175', expected '335169.3105175', error '0.0000000'
Test #10:
score: 0
Accepted
time: 2ms
memory: 4032kb
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.35850494345712036193
result:
ok found '411470.3585049', expected '411470.3585049', error '0.0000000'
Test #11:
score: 0
Accepted
time: 74ms
memory: 12240kb
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.00000000000000000000
result:
ok found '2000000.0000000', expected '2000000.0000000', error '0.0000000'
Test #12:
score: 0
Accepted
time: 75ms
memory: 12876kb
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:
540000.00000000001580247044
result:
ok found '540000.0000000', expected '540000.0000000', error '0.0000000'
Test #13:
score: 0
Accepted
time: 11ms
memory: 4388kb
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.89715295019539098575
result:
ok found '1823923.8971530', expected '1823923.8971530', error '0.0000000'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3836kb
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.73454094051004403809
result:
ok found '420530.7345409', expected '420530.7345409', error '0.0000000'
Test #15:
score: 0
Accepted
time: 251ms
memory: 25348kb
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.44078596616714094125
result:
ok found '1479667.4407860', expected '1479667.4407860', error '0.0000000'
Test #16:
score: 0
Accepted
time: 580ms
memory: 41416kb
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.95743987041737455002
result:
ok found '1945479.9574399', expected '1945479.9574399', error '0.0000000'
Test #17:
score: 0
Accepted
time: 3ms
memory: 4052kb
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.00000000000000000000
result:
ok found '500000.0000000', expected '500000.0000000', error '0.0000000'
Test #18:
score: 0
Accepted
time: 71ms
memory: 12224kb
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.31485497431414088965
result:
ok found '4987.3148550', expected '4987.3148550', error '0.0000000'
Test #19:
score: 0
Accepted
time: 297ms
memory: 23992kb
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.00000000000000000000
result:
ok found '145000.0000000', expected '145000.0000000', error '0.0000000'
Test #20:
score: 0
Accepted
time: 1ms
memory: 4380kb
input:
0 1000 0 1000 (!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!...
output:
623640.00000000000000000000
result:
ok found '623640.0000000', expected '623640.0000000', error '0.0000000'
Test #21:
score: 0
Accepted
time: 70ms
memory: 13088kb
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.00000138891685755112
result:
ok found '0.0000014', expected '0.0000014', error '0.0000000'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
0 1000 0 1000 (([-998,999,0]&[999,-1000,0])&[-1,-1,3])
output:
0.00000112725366188356
result:
ok found '0.0000011', expected '0.0000011', error '0.0000000'
Extra Test:
score: 0
Extra Test Passed