QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#317646 | #7730. Convex Checker | Djangle162857 | WA | 1ms | 4020kb | C++20 | 3.6kb | 2024-01-29 11:15:10 | 2024-01-29 11:15:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " == " << x << endl
#define el '\n'
typedef long long ll;
typedef double LD;
const int mod = 1000000007;
const int inf = 2147483647;
const int N = 200020;
const LD eps = 1e-12;
LD sqr(LD x) {
return x * x;
}
struct point {
LD x, y;
point operator+(const point &a) const {
return {x + a.x, y + a.y};
}
point operator-(const point &a) const {
return {x - a.x, y - a.y};
}
point operator*(const LD a) const {
return {a * x, a * y};
}
point operator/(const LD a) const {
return {x / a, y / a};
}
//?????
point rotate(LD t) const {
return {x * cos(t) - y * sin(y), x * sin(t) - y * cos(t)};
}
//????90?
point rotate_90() const {
return {-y, x};
}
point unit() const {
return *this / sqrt(sqr(x) + sqr(y));
}
};
struct line {
point s, t;
};
int sgn(LD x) {
return x > eps ? 1 : (x < -eps ? -1 : 0);
}
//????????
LD dis(const point &a, const point &b) {
return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}
//??
LD dot(const point &a, const point &b) {
return a.x * b.x + a.y * b.y;
}
//??
LD det(const point &a, const point &b) {
return a.x * b.y - a.y * b.x;
}
//?????
bool operator==(const point &a, const point &b) {
return sgn(dot(a - b, a - b)) == 0;
}
//??????????????????
bool turn_right(const point &a, const point &b, const point &c) {
return sgn(det(b - a, c - a)) < 0;
}
//????????????
vector<point> convex_hull(vector<point> b) {
sort(b.begin(), b.end(), [&](point x, point y) -> bool {
if (sgn(x.y - y.y))
return x.y < y.y;
return x.x < y.x;
});
vector<point> a;
a.push_back(b[0]);
for (int i = 1; i < b.size(); i++) {
if (b[i] == b[i - 1])
continue;
a.push_back(b[i]);
}
if (a.size() <= 2)
return a;
vector<point> ret;
for (int i = 0; i < (int)a.size(); i++) {
while (ret.size() > 1 &&
turn_right(ret[ret.size() - 2], ret[ret.size() - 1],
a[i])) {
ret.pop_back();
}
ret.push_back(a[i]);
}
int down_size = ret.size();
for (int i = a.size() - 2; i >= 0; i--) {
while (ret.size() > down_size &&
turn_right(ret[ret.size() - 2], ret[ret.size() - 1],
a[i])) {
ret.pop_back();
}
ret.push_back(a[i]);
}
ret.pop_back();
return ret;
}
bool cmp(const point &x, const point &y) {
if (sgn(x.y - y.y))
return x.y < y.y;
return x.x < y.x;
}
void solve() {
int n;
LD ans = 0.00;
cin >> n;
vector<point> a, v, vec1, vec2;
for (int i = 1; i <= n; i++) {
point res;
cin >> res.x >> res.y;
a.push_back(res);
if (i > 1)
vec1.push_back(a[i - 1] - a[i - 2]);
}
vec1.push_back(a[0] - a[n - 1]);
v = convex_hull(a);
for (int i = 0; i < v.size(); i++) {
if (i == v.size() - 1) {
vec2.push_back(v[0] - v[i]);
} else
vec2.push_back(v[i + 1] - v[i]);
}
if (vec1.size() != vec2.size()) {
cout << "No" << el;
return;
}
sort(vec1.begin(), vec1.end(), cmp);
sort(vec2.begin(), vec2.end(), cmp);
int flag = 0;
for (int i = 0; i < vec1.size(); i++) {
if (vec1[i] != vec2[i]) {
flag = 1;
break;
}
}
if (flag == 0) {
cout << "Yes" << el;
return;
}
flag = 0;
vec2.clear();
for (int i = 0; i < v.size(); i++) {
if (i == v.size() - 1) {
vec2.push_back(v[i] - v[0]);
} else
vec2.push_back(v[i] - v[i + 1]);
}
sort(vec2.begin(), vec2.end(), cmp);
for (int i = 0; i < vec1.size(); i++) {
if (vec1[i] != vec2[i]) {
flag = 1;
break;
}
}
if (flag == 0) {
cout << "Yes" << el;
return;
} else {
cout << "No" << el;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
/*
7
2 1
0 0
1 2
2 2
4 2
1 3
3 3
5
0 0
2 1
4 2
3 3
1 3
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4020kb
input:
3 0 0 1 0 0 1
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
4 0 0 0 1 1 1 1 0
output:
Yes
result:
ok answer is YES
Test #3:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
4 0 0 0 3 1 2 1 1
output:
Yes
result:
ok answer is YES
Test #4:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
3 0 0 0 0 0 0
output:
No
result:
ok answer is NO
Test #5:
score: 0
Accepted
time: 0ms
memory: 4016kb
input:
5 1 0 4 1 0 1 2 0 3 2
output:
No
result:
ok answer is NO
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 4012kb
input:
5 0 0 1000000000 0 1000000000 500000000 1000000000 1000000000 0 1000000000
output:
Yes
result:
wrong answer expected NO, found YES