結果

問題 No.199 星を描こう
ユーザー koba-e964koba-e964
提出日時 2015-07-06 15:43:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 75,512 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 18:40:35
合計ジャッジ時間 1,593 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;
typedef complex<double> comp;



/*
 * Convex hull
 * Requirement, <vector>, <complex>, std, comp
 * Note: ps is modified
 * reference : arihon (ISBN-10: 4839931992)
 */
struct cmp_x {
  bool operator()(const comp &x, const comp &y) {
    return x.real() < y.real();
  }
};
vector<comp> convex_hull(vector<comp> &ps) {
  sort(ps.begin(), ps.end(), cmp_x());
  const int n = ps.size();
  int k = 0;
  vector<comp> qs(2 * n);
  // lower
  for (int i = 0; i < n; ++i) {
    while (k > 1 &&  (conj(qs[k - 1] - qs[k - 2]) * (ps[i] - qs[k - 1])).imag() <= 0) {
      k--;
    }
    qs[k++] = ps[i];
  }
  // upper
  for (int i = n - 2, t = k; i >= 0; --i) {
    while (k > t && (conj(qs[k - 1] - qs[k - 2]) * (ps[i] - qs[k - 1])).imag() <= 0) {
      k--;
    }
    qs[k++] = ps[i];
  }
  qs.resize(k - 1);
  return qs;
}


int main(void){
  double ax = 0, ay = 0;
  vector<comp> ps;
  REP(i, 0, 5) {
    double p, q;
    cin >> p >> q;
    ps.push_back(comp(p, q));
  }
  cout << (convex_hull(ps).size() == 5 ? "YES" : "NO") << endl;
}
0