QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#317630 | #7730. Convex Checker | Djangle162857 | WA | 0ms | 3944kb | C++20 | 4.0kb | 2024-01-29 10:43:11 | 2024-01-29 10:43:11 |
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 same_dir(const line &a, const line &b) {
return sgn(det(a.t - a.s, b.t - b.s)) == 0 &&
sgn(dot(a.t - a.s, b.t - b.s)) > 0;
}
//??????????????????
bool turn_left(const point &a, const point &b, const point &c) {
return sgn(det(b - a, c - a)) > 0;
}
//??????????????????
bool turn_right(const point &a, const point &b, const point &c) {
return sgn(det(b - a, c - a)) < 0;
}
//???????
bool point_on_line(const point &a, const line &l) {
return sgn(det(l.s - a, a - l.t)) == 0;
}
//???????
bool point_on_segment(const point &a, const line &l) {
return sgn(det(l.s - a, a - l.t)) == 0 &&
sgn(dot(l.s - a, a - l.t)) <= 0;
}
//???????????(????)
bool two_side(const point &a, const point &b, const line &c) {
return sgn(det(a - c.s, c.t - c.s)) *
sgn(det(b - c.s, c.t - c.s)) ==
-1;
}
//??????
bool inter_judge(const line &a, const line &b) {
if (point_on_segment(a.s, b) || point_on_segment(a.t, b) ||
point_on_segment(b.s, a) || point_on_segment(b.t, a))
return true;
return two_side(a.s, a.t, b) && two_side(b.s, b.t, a);
}
//?????(????????)
point line_intersect(const line &a, const line &b) {
LD u = det(a.t - a.s, b.s - a.s);
LD v = det(a.t - a.s, b.t - a.s);
return (b.s * v + b.t * u) / (u + v);
}
//???????
LD dist_point_to_line(const point &a, const line &b) {
return fabs(det(b.t - b.s, a - b.s) / dis(b.s, b.t));
}
//???????
LD dist_point_to_segment(const point &a, const line &b) {
if (sgn(dis(b.t, b.s)) == 0) {
return dis(a, b.s);
}
if (sgn(dot(b.s - a, b.t - b.s)) * sgn(dot(b.t - a, b.t - b.s)) <=
0) {
return dist_point_to_line(a, b);
}
return min(dis(a, b.s), dis(a, b.t));
}
//??(?????????)
vector<point> convex_hull(vector<point> b) {
sort(b.begin(), b.end(), [&](point x, point y) -> bool {
if (sgn(x.x - y.x))
return x.x < y.x;
return x.y < y.y;
});
vector<point> a;
a.push_back(b[0]);
for (int i = 1; i < b.size(); i++) {
if (b[i] != b[i - 1])
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_left(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_left(ret[ret.size() - 2], ret[ret.size() - 1],
a[i])) {
ret.pop_back();
}
ret.push_back(a[i]);
}
ret.pop_back();
return ret;
}
void solve() {
int n;
LD ans = 0.00;
cin >> n;
vector<point> a, v;
for (int i = 1; i <= n; i++) {
point res;
cin >> res.x >> res.y;
a.push_back(res);
}
v = convex_hull(a);
if(v.size()==n){
cout<<"Yes"<<el;
}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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3732kb
input:
3 0 0 1 0 0 1
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3708kb
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: 3944kb
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: 3776kb
input:
3 0 0 0 0 0 0
output:
No
result:
ok answer is NO
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3880kb
input:
5 1 0 4 1 0 1 2 0 3 2
output:
Yes
result:
wrong answer expected NO, found YES