結果

問題 No.199 星を描こう
ユーザー tottoripaper
提出日時 2015-04-29 00:25:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,347 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 53,204 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-30 03:24:06
合計ジャッジ時間 1,678 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:83:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   83 |         scanf("%lf %lf", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

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