結果
問題 | No.199 星を描こう |
ユーザー |
|
提出日時 | 2023-06-26 01:53:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,878 bytes |
コンパイル時間 | 2,071 ms |
コンパイル使用メモリ | 177,088 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 18:47:04 |
合計ジャッジ時間 | 3,250 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORE(i, a, b) for (int i = (a); i <= (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define trav(a, x) for (auto &a : x) #define f first #define s second #define bk back() #define pb push_back #define sz(x) int((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) int N, Q; const int MX = 2e5 + 5; using T = long long; // or long long const T EPS = 1e-9; // might want to change using P = pair<T, T>; using vP = vector<P>; using Line = pair<P, P>; T sq(T a) { return a * a; } // square T norm(const P &p) { return sq(p.f) + sq(p.s); } // x^2 + y^2 // basic operations P operator-(const P &l, const P &r) { return P(l.f - r.f, l.s - r.s); } T cross(const P &a, const P &b) { return a.f * b.s - a.s * b.f; } // cross product T cross(const P &p, const P &a, const P &b) { // cross product return cross(a - p, b - p); } using vi = vector<int>; using vP = vector<P>; int convex_hull(const vP &v) { int ind = int(min_element(all(v)) - begin(v)); vi cand, hull{ind}; F0R(i, sz(v)) if (v[i] != v[ind]) cand.pb(i); sort(all(cand), [&](int a, int b) { // sort by angle, tiebreak by distance P x = v[a] - v[ind], y = v[b] - v[ind]; T t = cross(x, y); return t != 0 ? t > 0 : norm(x) < norm(y); }); trav(c, cand) { // for every point while (sz(hull) > 1 && cross(v[end(hull)[-2]], v[hull.bk], v[c]) <= 0) { hull.pop_back(); // pop until counterclockwise and size > 1 } hull.pb(c); } return (int)hull.size(); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); vP points(5); for (int i = 0; i < 5; ++i) { int x, y; cin >> x >> y; points[i] = P(x, y); } if (convex_hull(points) == 5) cout << "YES"; else cout << "NO"; return 0; }