結果

問題 No.199 星を描こう
ユーザー koyopro
提出日時 2015-10-02 13:48:17
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 164,704 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-30 03:43:07
合計ジャッジ時間 2,557 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
struct P {
    int x, y;
    P(){};
    P(int _x, int _y): x(_x), y(_y){};

    P operator - (P q) {
        return P(x - q.x, y - q.y);
    }
    int det(P q) {
        return x * q.y - y * q.x;
    }
};
vector<P> ps;

bool comp(P p, P q) {
    if (p.x != q.x) return p.x < q.x;
    return p.y < q.y;
}

vector<P> convex_hull(vector<P> *ps) {
    sort(ps->begin(), ps->end(), comp);
    vector<P> q(ps->size() * 2);
    int k = 0;
    REP(i,ps->size()) {
        while (k >= 2 && (q[k-1]-q[k-2]).det((*ps)[i]-q[k-1]) <= 0) k--;
        q[k++] = (*ps)[i];
    }
    int t = k;
    RREP(i,ps->size()-1) {
        while (k > t && (q[k-1]-q[k-2]).det((*ps)[i]-q[k-1]) <= 0) k--;
        q[k++] = (*ps)[i];
    }
    q.resize(k-1);
    return q;
}

signed main()
{
    int x,y;
    REP(i,5) {
        cin >> x >> y;
        ps.push_back(P(x,y));
    }
    cout << ((convex_hull(&ps).size() == 5) ? "YES" : "NO") << endl;
    return 0;
}
0