結果
| 問題 |
No.199 星を描こう
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-29 16:59:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,525 bytes |
| コンパイル時間 | 189 ms |
| コンパイル使用メモリ | 28,904 KB |
| 最終ジャッジ日時 | 2024-11-14 19:03:58 |
| 合計ジャッジ時間 | 856 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:16:1: error: ‘vector’ does not name a type
16 | vector<Point> _alg(vector<Point> points) {
| ^~~~~~
main.cpp:30:1: error: ‘vector’ does not name a type
30 | vector<Point> convex_hull(vector<Point> points) {
| ^~~~~~
main.cpp: In function ‘int main()’:
main.cpp:43:3: error: ‘vector’ was not declared in this scope
43 | vector<Point> points(5);
| ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
2 | #include <algorithm>
+++ |+#include <vector>
3 | using namespace std;
main.cpp:43:15: error: expected primary-expression before ‘>’ token
43 | vector<Point> points(5);
| ^
main.cpp:43:17: error: ‘points’ was not declared in this scope; did you mean ‘Point’?
43 | vector<Point> points(5);
| ^~~~~~
| Point
main.cpp:49:13: error: ‘convex_hull’ was not declared in this scope
49 | int res = convex_hull(points).size();
| ^~~~~~~~~~~
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;
}