QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#373057 | #2434. Single Cut of Failure | TWTP_TCTF | WA | 0ms | 3760kb | C++14 | 4.9kb | 2024-04-01 00:39:29 | 2024-04-01 00:39:31 |
Judging History
answer
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e6 + 2, MOD = 998244353;
ld eps = 0.5;
struct pt {
long long x, y;
pt() {}
pt(long long _x, long long _y) : x(_x), y(_y) {}
pt operator-(const pt &p) const { return pt(x - p.x, y - p.y); }
long long cross(const pt &p) const { return x * p.y - y * p.x; }
long long cross(const pt &a, const pt &b) const { return (a - *this).cross(b - *this); }
};
int sgn(const long long &x) { return x >= 0 ? x ? 1 : 0 : -1; }
bool inter1(long long a, long long b, long long c, long long d) {
if (a > b)
swap(a, b);
if (c > d)
swap(c, d);
return max(a, c) <= min(b, d);
}
bool check_inter(const pt &a, const pt &b, const pt &c, const pt &d) {
if (c.cross(a, d) == 0 && c.cross(b, d) == 0)
return inter1(a.x, b.x, c.x, d.x) && inter1(a.y, b.y, c.y, d.y);
return sgn(a.cross(b, c)) != sgn(a.cross(b, d)) &&
sgn(c.cross(d, a)) != sgn(c.cross(d, b));
}
vector<pair<pt, pt>> v;
bool check(pt a, pt b) {
for (auto i: v) {
if (!check_inter(a, b, i.first, i.second))return false;
}
return true;
}
vector<ld> solve(int w, int h) {
ll l1 = 0, r1 = h, l2 = 0, r2 = h;
for (int i = 0; i < v.size(); i++) {
if (v[i].first.x > v[i].second.x)swap(v[i].first, v[i].second);
}
vector<pair<ll, ll> > rem;
for (auto i: v) {
if (i.first.x > 0 && i.second.x < w)continue;
if (i.first.x == 0 && i.second.y == h) {
l1 = max(l1, i.first.y);
} else if (i.first.x == 0 && i.second.y == 0) {
r1 = min(r1, i.first.y);
} else if (i.first.x == 0) {
rem.push_back({i.first.y, i.second.y});
} else if (i.first.y == h) {
l2 = max(l2, i.second.y);
} else if (i.first.y == 0) {
r2 = min(r2, i.second.y);
} else {
assert(false);
}
}
if (l1 >= r1 || l2 >= r2)return {};
if (rem.empty()) {
return {0, l1 + eps, (ld) w, l2 + eps};
}
sort(rem.begin(), rem.end());
stack<ll> st;
st.push(0);
for (int i = rem.size() - 1; i >= 0; i--) {
st.push(max(st.top(), rem[i].second));
}
if (rem[0].first > l1 && st.top() < r2) {
return {0, l1 + eps, (ld) w, r2 - eps};
}
for (int i = 0; i < rem.size(); i++) {
st.pop();
l1 = max(l1, rem[i].first);
r2 = min(r2, rem[i].second);
if (l1 >= r1 || l2 >= r2)return {};
if (i + 1 < rem.size() && rem[i + 1].first <= l1)continue;
if (st.top() < r2) {
return {0, l1 + eps, (ld) w, r2 - eps};
}
}
return {};
}
void doWork() {
int n, w, h;
cin >> n >> w >> h;
w *= 2;
h *= 2;
for (int i = 0; i < n; i++) {
pt a, b;
a.x *= 2, a.y *= 2;
b.x *= 2, b.y *= 2;
cin >> a.x >> a.y;
cin >> b.x >> b.y;
v.push_back({a, b});
}
if (check({1, 0}, {w, h - 1})) {
cout << "1\n";
cout << fixed << eps << " " << 0 << " " << w / 2 << " " << h / 2 - eps;
return;
}
if (check({0, 1}, {w - 1, h})) {
cout << "1\n";
cout << fixed << 0 << " " << eps << " " << w / 2 - eps << " " << h / 2;
return;
}
if (check({0, h - 1}, {w - 1, 0})) {
cout << "1\n";
cout << fixed << 0 << " " << h / 2 - eps << " " << w / 2 - eps << " " << 0;
return;
}
if (check({1, h}, {w, 1})) {
cout << "1\n";
cout << fixed << eps << " " << h / 2 << " " << w / 2 << " " << eps;
return;
}
w /= 2;
h /= 2;
for (int i = 0; i < n; i++) {
v[i].first.x /= 2, v[i].first.y /= 2;
v[i].second.x /= 2, v[i].second.y /= 2;
}
vector<ld> temp = solve(w, h);
if (!temp.empty()) {
cout << "1\n";
for (auto i: temp)cout << fixed << i << " ";
return;
}
for (int i = 0; i < v.size(); i++) {
swap(v[i].first.x, v[i].first.y);
swap(v[i].second.x, v[i].second.y);
}
temp = solve(h, w);
if (!temp.empty()) {
cout << "1\n";
swap(temp[0], temp[1]);
swap(temp[2], temp[3]);
for (auto i: temp)cout << fixed << i << " ";
return;
}
cout << "2\n";
cout << fixed << eps << " " << 0 << " " << w - eps << " " << h;
cout << "\n";
cout << fixed << eps << " " << h << " " << w - eps << " " << 0;
}
int main() {
IO
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << ": ";
doWork();
}
}
// cout << 0.2 + 0.8 / 2 * (0.1 + 0.9 * 0.9 / 10) + 0.8 / 2 / 10;
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3760kb