結果
| 問題 |
No.199 星を描こう
|
| コンテスト | |
| ユーザー |
e-mon
|
| 提出日時 | 2015-04-30 01:07:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,725 bytes |
| コンパイル時間 | 1,694 ms |
| コンパイル使用メモリ | 164,204 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-30 03:33:47 |
| 合計ジャッジ時間 | 2,812 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
struct P{
double x, y;
P() {}
P(double x, double y) : x(x), y(y){
}
P operator + (P p){
return P(x + p.x, y + p.y);
}
P operator - (P p){
return P(x - p.x, y - p.y);
}
P operator * (double d){
return P(d*x, d*y);
}
double dot(P p){ //pとの内積
return x * p.x + y * p.y;
}
double det(P p){ //pとの外積
return x * p.y - p.x * y;
}
double dist(P p){ //pとの距離の2乗
return (x-p.x)*(x-p.x) + (y-p.y)*(y-p.y);
}
//辞書順での比較
bool operator <(const struct P &e) const{
return x == e.x? (y < e.y) : x < e.x;
}
bool operator >(const struct P &e) const{
return x == e.x? (y > e.y) : x > e.x;
}
};
vector<P> convex_hull(P* ps, int n){
sort(ps, ps + n, [](const P& p, const P& q) -> bool { return p<q;});
int k = 0;
vector<P> qs(n*2);
//下側
for (int i = 0;i < n;i++){
while (k > 1 && (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0) k--;
qs[k++] = ps[i];
}
//下側
for (int i = n - 2, t = k;i >= 0;i--){
while (k > t && (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0) k--;
qs[k++] = ps[i];
}
qs.resize(k-1);
return qs;
}
int main(){
int N = 5;
P ps[5];
for(int i=0;i<N;i++){
cin >> ps[i].x >> ps[i].y ;
}
auto qs = convex_hull(ps,N);
if(qs.size() == 5){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
return 0;
}
e-mon