結果
問題 | No.199 星を描こう |
ユーザー |
![]() |
提出日時 | 2018-08-01 22:04:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 4,214 bytes |
コンパイル時間 | 2,244 ms |
コンパイル使用メモリ | 176,780 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-19 16:57:18 |
合計ジャッジ時間 | 2,959 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h>using namespace std;using VS = vector<string>; using LL = long long;using VI = vector<int>; using VVI = vector<VI>;using PII = pair<int, int>; using PLL = pair<LL, LL>;using VL = vector<LL>; using VVL = vector<VL>;#define ALL(a) begin((a)),end((a))#define RALL(a) (a).rbegin(), (a).rend()#define SZ(a) int((a).size())#define SORT(c) sort(ALL((c)))#define RSORT(c) sort(RALL((c)))#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)#define debug(x) cerr << #x << ": " << x << endlconst int INF = 1e9; const LL LINF = 1e16;const LL MOD = 1000000007; const double PI = acos(-1.0);int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };/* ----- 2018/07/31 Problem: yukicoder 199 / Link: http://yukicoder.me/problems/no/199 ----- *//* ------問題------XY座標上の点が5つ与えられる。点を線で繋いで星が描けるかどうか判定せよ。※星の定義を図で説明します。(A)はきれいな星になっていますね。(B)は赤の矢印で示した部分が出ていないので星ではありません。(C)はかなり歪んでいますが星です。シルエットにしたとき5つのとんがりが無いとダメという認識でお願いします。-----問題ここまで----- *//* -----解説等---------解説ここまで---- */using Double = long double;const double EPS = 1e-9;typedef struct Point {Double x, y;Point(Double x_, Double y_) : x(x_), y(y_) {}bool operator < (const Point& a) const {return fabs(x - a.x) < EPS ? y + EPS < a.y : x + EPS < a.x;}bool operator > (const Point& a) const {return a < *this;}bool operator == (const Point& a) const {return !(a < *this) && !(a > *this);}Point operator + (const Point& a) const {return Point(x + a.x, y + a.y);}Point operator - (const Point& a) const {return Point(x - a.x, y - a.y);}Point operator * (const Point& a) const {return Point(x * a.x, y * a.y);}Point operator / (const Point& a) const {return Point(x / a.x, y / a.y);}Point operator * (const Double& d) const {return Point(x * d, y * d);}Point operator / (const Double& d) const {return Point(x / d, y / d);}} Vector;// ノルムDouble norm(const Point& a) {return a.x * a.x + a.y * a.y;}// サイズDouble abs(const Point& a) {return sqrt(norm(a));}// 内積Double dot(const Vector& a, const Vector& b) {return a.x * b.x + a.y * b.y;}// 外積Double cross(const Vector& a, const Vector& b) {return a.x * b.y - a.y * b.x;}// counter clockwiseint ccw(const Point& a, const Point& b, const Point& c) {Vector ba = b - a, ca = c - a;if (cross(ba, ca) > EPS) return +1; // ccwif (cross(ba, ca) < -EPS) return -1; // cwif (dot(ba, ca) < -EPS) return +2; // c-a-bif (abs(ba) + EPS < abs(ca)) return -2; // a-b-creturn 0; // a-c-b}// 多角形構造体struct Polygon {vector< Point > vert;Polygon(int n = 3) : vert(n, Point(0, 0)) {}Double area() const {Double res = 0;int v_size = size();FOR(i, 0, v_size) res += cross(at(i), at(i + 1));return fabs(res) / 2.;}Point at(int i) const {i %= size();return vert[i];}int size() const { return SZ(vert); }};// 凸包Polygon convex_hull(vector< Point > vp) {if (SZ(vp) <= 1) {Polygon ret;ret.vert = vp;return ret;}int n = SZ(vp), k = 0;sort(ALL(vp));vector< Point > ch(2 * n, Point(0, 0));for (int i = 0; i < n; ch[k++] = vp[i++]) {while (k >= 2 && ccw(ch[k - 2], ch[k - 1], vp[i]) <= 0) --k;}for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = vp[i--]) {while (k >= t && ccw(ch[k - 2], ch[k - 1], vp[i]) <= 0) --k;}Polygon res(k - 1);FOR(i, 0, k - 1) res.vert[i] = ch[i];return res;}int main() {cin.tie(0);ios_base::sync_with_stdio(false);int N = 5;vector<Point>ps;FOR(i, 0, N) {int x, y;cin >> x >> y;ps.push_back(Point(x, y));}int ok = (convex_hull(ps).size() == 5);cout << (ok ? "YES" : "NO") << "\n";return 0;}