結果
| 問題 | No.199 星を描こう |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-29 16:59:20 |
| 言語 | C++11(old_compat) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,525 bytes |
| 記録 | |
| コンパイル時間 | 1,427 ms |
| コンパイル使用メモリ | 175,804 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 16:02:34 |
| 合計ジャッジ時間 | 2,047 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:46:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | scanf("%d%d", &p.x, &p.y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
ソースコード
#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;
}