結果

問題 No.199 星を描こう
ユーザー tottoripapertottoripaper
提出日時 2015-04-29 00:25:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,347 bytes
コンパイル時間 619 ms
コンパイル使用メモリ 56,320 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 18:35:19
合計ジャッジ時間 1,690 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// Wrongri-La Shower
// まともな幾何ライブラリをつくろうな

#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>

// double
struct P{
    P(){}
    P(double _r, double _i):r(_r), i(_i){}
    void real(const double& v){r = v;}
    void imag(const double& v){i = v;}
    P& operator-=(const P& rhs){
        this->r -= rhs.r;
        this->i -= rhs.i;
        return *this;
    }
    bool operator<(const P& rhs) const{
        if(this->r == rhs.r){
            return this->i < rhs.i;
        }
        return this->r < rhs.r;
    }
    double r, i;
};

double real(const P& p){return p.r;}
double imag(const P& p){return p.i;}
double norm(const P& p){double r = real(p), i = imag(p); return r * r + i * i;}
double dist(const P& p){return std::sqrt(norm(p));}

P operator+(const P& lhs, const P& rhs){
    return P(real(lhs)+real(rhs), imag(lhs)+imag(rhs));
}
P operator-(const P& lhs, const P& rhs){
    return P(real(lhs)-real(rhs), imag(lhs)-imag(rhs));
}
P operator-(const P& p){
    return P(-real(p), -imag(p));
}

double cross(const P& lhs, const P& rhs){
    return real(lhs)*imag(rhs) - imag(lhs)*real(rhs);
}

double dot(const P& lhs, const P& rhs){
    return real(lhs)*real(rhs) + imag(lhs)*imag(rhs);
}

// 全然つかったことのないccw
int ccw(P a, P b, P c){
    b -= a; c -= a;
    if(cross(b, c) > 0)return 1; // counter clock wise
    if(cross(b, c) < 0)return -1; // clock wise
    if(dot(b, c) < 0)return 2; // B A C
    if(norm(b) < norm(c))return -2; // A B C
    return 0; // A C B
}

// Convex-Hull
std::vector<P> convex_hull(std::vector<P> ps){
    int n = ps.size(), k = 0;
    std::sort(ps.begin(), ps.end());
    
    std::vector<P> ch(2*n);
    for(int i=0;i<n;ch[k++]=ps[i++]){ // 下
        while(k>=2&&ccw(ch[k-2], ch[k-1], ps[i])<=0){--k;} // 反時計になるよう調整
    }
    for(int i=n-2, t=k+1;i>=0;ch[k++]=ps[i--]){ // 上
        while(k>=t&&ccw(ch[k-2], ch[k-1], ps[i])<=0){--k;}
    }
    
    ch.resize(k-1); // 輪を閉じる部分(最初と最後)の重複を除く
    return ch;
}

int main(){
    std::vector<P> polygon;
    for(int i=0;i<5;i++){
        double x, y;
        scanf("%lf %lf", &x, &y);
        polygon.emplace_back(x, y);
    }

    if(convex_hull(polygon).size() == 5){
        puts("YES");
    }else{
        puts("NO");
    }
}
0