QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#419333 | #4189. Flappy Bird | zezoo050# | WA | 1ms | 3740kb | C++20 | 2.0kb | 2024-05-23 20:26:18 | 2024-05-23 20:26:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct point {
long long x, y;
bool operator<(point other) const {
return (1LL * x * other.y < 1LL * other.x * y);
}
bool operator>(point other) const {
return (1LL * x * other.y > 1LL * other.x * y);
}
void reduce() {
long long g = __gcd(x, y);
x /= g;
y /= g;
}
};
point slope(point p1, point p2) {
// cerr << p1.x << ' ' << p1.y << ' ' << p2.x << ' ' << p2.y << '\n';
point ret;
ret.x = p2.y - p1.y;
ret.y = p2.x - p1.x;
ret.reduce();
// cerr << ret.x << ' ' << ret.y << '\n';
return ret;
}
const int N = 1e6 + 5;
pair<point, point> a[N];
void tc() {
int n;
cin >> a[0].first.x >> a[0].first.y;
a[0].second = a[0].first;
int tex, tey;
cin >> tex >> tey;
cin >> n;
a[n + 1].second = a[n + 1].first = {tex, tey};
for (int i = 1; i <= n; i++) {
int x, y1, y2;
cin >> x >> y1 >> y2;
a[i].first = {x, y1};
a[i].second = {x, y2};
}
// 0 --- -- n+1
point cur = a[0].first;
cout << cur.x << ' ' << cur.y << '\n';
point l = {-INT_MAX, 1}, r = {INT_MAX, 1};
for (int i = 1; i <= n + 1; i++) {
point s1 = slope(cur, a[i].first);
point s2 = slope(cur, a[i].second);
if (s1 > r) {
cur = a[i - 1].second;
l = {-INT_MAX, 1}, r = {INT_MAX, 1};
cout << cur.x << ' ' << cur.y << '\n';
} else if (s2 < l) {
cur = a[i - 1].first;
l = {-INT_MAX, 1}, r = {INT_MAX, 1};
cout << cur.x << ' ' << cur.y << '\n';
}
l = max(l, s1);
r = min(r, s2);
}
cout << tex << ' ' << tey << '\n';
}
signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
tc();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3736kb
input:
0 0 10 0 1 5 -10 10
output:
0 0 10 0
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
0 0 10 0 4 2 1 3 4 2 3 7 0 2 9 -2 -1
output:
0 0 4 2 9 -1 10 0
result:
ok
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3740kb
input:
0 0 7 -12 3 1 -1 1 2 -3 3 5 -12 -8
output:
0 0 1 1 2 3 7 -12
result:
wrong answer Output doesn't match expected line