結果

問題 No.199 星を描こう
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-05-29 16:59:20
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,525 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 32,056 KB
最終ジャッジ日時 2023-08-28 18:39:35
合計ジャッジ時間 524 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:16:1: error: ‘vector’ does not name a type; did you mean ‘qecvt_r’?
 vector<Point> _alg(vector<Point> points) {
 ^~~~~~
 qecvt_r
main.cpp:30:1: error: ‘vector’ does not name a type; did you mean ‘qecvt_r’?
 vector<Point> convex_hull(vector<Point> points) {
 ^~~~~~
 qecvt_r
main.cpp: In function ‘int main()’:
main.cpp:43:3: error: ‘vector’ was not declared in this scope
   vector<Point> points(5);
   ^~~~~~
main.cpp:43:3: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
main.cpp:3:1:
+#include <vector>
 using namespace std;
main.cpp:43:3:
   vector<Point> points(5);
   ^~~~~~
main.cpp:43:15: error: expected primary-expression before ‘>’ token
   vector<Point> points(5);
               ^
main.cpp:43:17: error: ‘points’ was not declared in this scope
   vector<Point> points(5);
                 ^~~~~~
main.cpp:43:17: note: suggested alternative: ‘Point’
   vector<Point> points(5);
                 ^~~~~~
                 Point
main.cpp:49:13: error: ‘convex_hull’ was not declared in this scope
   int res = convex_hull(points).size();
             ^~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <algorithm>
using namespace std;

class Point {
  public:
    int x, y;
    bool operator < (const Point& other) const;
};
int cross_product(Point o, Point a, Point b) { return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x); }
bool Point::operator < (const Point& other) const { return x == other.x ? y < other.y : x < other.x; }

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

vector<Point> _alg(vector<Point> points) {
  vector<Point> res;
  int sz = 0;
  for(Point p : points) {
    while(sz > 1 && cross_product(res[sz-2], res[sz-1], p) <= 0) {
      res.pop_back();
      sz -= 1;
    }
    res.push_back(p);
    sz += 1;
  }
  return res;
}

vector<Point> convex_hull(vector<Point> points) {
  sort(points.begin(), points.end());
  if(points.size() <= 1) { return points; }
  vector<Point> lower = _alg(points);
  reverse(points.begin(), points.end());
  vector<Point> upper = _alg(points);
  vector<Point> res;
  for(int i : range(lower.size()-1)) { res.push_back(lower[i]); }
  for(int i : range(upper.size()-1)) { res.push_back(upper[i]); }
  return res;
}

int main(void) {
  vector<Point> points(5);
  for(int i : range(5)) {
    Point p;
    scanf("%d%d", &p.x, &p.y);
    points[i] = p;
  }
  int res = convex_hull(points).size();
  puts(res == 5 ? "YES" : "NO");
  return 0;
}
0