結果
問題 | No.199 星を描こう |
ユーザー | srjywrdnprkt |
提出日時 | 2022-12-29 03:39:35 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,386 bytes |
コンパイル時間 | 1,246 ms |
コンパイル使用メモリ | 114,324 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 05:48:02 |
合計ジャッジ時間 | 2,224 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 1 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 1 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 1 ms
5,248 KB |
testcase_24 | AC | 1 ms
5,248 KB |
testcase_25 | AC | 1 ms
5,248 KB |
testcase_26 | AC | 1 ms
5,248 KB |
testcase_27 | AC | 1 ms
5,248 KB |
ソースコード
#include <iostream> #include <vector> #include <cmath> #include <map> #include <set> #include <iomanip> #include <queue> #include <algorithm> #include <numeric> #include <deque> #include <sstream> using namespace std; template <typename T> struct point{ T x, y; }; //judge if line AB intersects line CD template <typename T> bool intersect(point<T> &a, point<T> &b, point<T> &c, point<T> &d){ bool ans = 1; T s, t; s = (a.x - b.x) * (c.y - a.y) - (a.y - b.y) * (c.x - a.x); t = (a.x - b.x) * (d.y - a.y) - (a.y - b.y) * (d.x - a.x); if (s*t > 0) ans = 0; s = (c.x - d.x) * (a.y - c.y) - (c.y - d.y) * (a.x - c.x); t = (c.x - d.x) * (b.y - c.y) - (c.y - d.y) * (b.x - c.x); if (s*t > 0) ans = 0; return ans; } //Euclidean distance between A and B template <typename T> T dist(point<T> &a, point<T> &b, bool square = false){ T d = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); return (square ? d : sqrt(d)); } //Inner product of vectors AB and CD template <typename T> T innerp(point<T> &a, point<T> &b, point<T> &c, point<T> &d){ return (b.x - a.x) * (d.x - c.x) + (b.y - a.y) * (d.y - c.y); } //Cross product of vectors AB and CD template <typename T> T crossp(point<T> &a, point<T> &b, point<T> &c, point<T> &d){ return (b.x - a.x) * (d.y - c.y) - (b.y - a.y) * (d.x - c.x); } //Calculate the area of triangle ABC template <typename T> T heron(point<T> &a, point<T> &b, point<T> &c){ return abs(crossp(a, b, a, c)) / 2; } //Convex Hull(Smallest Convex set containing all given points) //Grahum Scan (O(NlogN)) template <typename T> vector<point<T>> convex_hull(vector<point<T>> P){ sort(P.begin(), P.end(), [](point<T> &p1, point<T> &p2) { if (p1.x != p2.x) return p1.x < p2.x; return p1.y < p2.y; }); int N=P.size(), k=0, t; vector<point<T>> res(N*2); for (int i=0; i<N; i++){ while(k > 1 && crossp(res[k-2], res[k-1], res[k-1], P[i]) <= 0) k--; res[k] = P[i]; k++; } t = k; for (int i=N-2; i>=0; i--){ while(k > t && crossp(res[k-2], res[k-1], res[k-1], P[i]) <= 0) k--; res[k] = P[i]; k++; } res.resize(k-1); return res; } int main(){ vector<point<int>> P(5); for (auto &[x, y] : P) cin >> x >> y; cout << (convex_hull(P).size() == 5 ? "YES" : "NO") << endl; return 0; }