結果
| 問題 | 
                            No.199 星を描こう
                             | 
                    
| コンテスト | |
| ユーザー | 
                             srjywrdnprkt
                         | 
                    
| 提出日時 | 2022-12-29 03:39:35 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 32 ms / 2,000 ms | 
| コード長 | 2,386 bytes | 
| コンパイル時間 | 1,235 ms | 
| コンパイル使用メモリ | 110,004 KB | 
| 最終ジャッジ日時 | 2025-02-09 21:41:38 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <sstream>
using namespace std;
template <typename T>
struct point{
    T x, y;
};
//judge if line AB intersects line CD
template <typename T>
bool intersect(point<T> &a, point<T> &b, point<T> &c, point<T> &d){
    bool ans = 1;
    T s, t;
    s = (a.x - b.x) * (c.y - a.y) - (a.y - b.y) * (c.x - a.x);
    t = (a.x - b.x) * (d.y - a.y) - (a.y - b.y) * (d.x - a.x);
    if (s*t > 0) ans = 0;
    s = (c.x - d.x) * (a.y - c.y) - (c.y - d.y) * (a.x - c.x);
    t = (c.x - d.x) * (b.y - c.y) - (c.y - d.y) * (b.x - c.x);
    if (s*t > 0) ans = 0;
    return ans;
}
//Euclidean distance between A and B
template <typename T>
T dist(point<T> &a, point<T> &b, bool square = false){
    T d = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
    return (square ? d : sqrt(d));
}
//Inner product of vectors AB and CD
template <typename T>
T innerp(point<T> &a, point<T> &b, point<T> &c, point<T> &d){
    return (b.x - a.x) * (d.x - c.x) + (b.y - a.y)  * (d.y - c.y);
}
//Cross product of vectors AB and CD
template <typename T>
T crossp(point<T> &a, point<T> &b, point<T> &c, point<T> &d){
    return (b.x - a.x) * (d.y - c.y) - (b.y - a.y) * (d.x - c.x);
}
//Calculate the area of triangle ABC
template <typename T>
T heron(point<T> &a, point<T> &b, point<T> &c){
    return abs(crossp(a, b, a, c)) / 2;
}
//Convex Hull(Smallest Convex set containing all given points)
//Grahum Scan (O(NlogN))
template <typename T>
vector<point<T>> convex_hull(vector<point<T>> P){
    sort(P.begin(), P.end(), [](point<T> &p1, point<T> &p2) {
        if (p1.x != p2.x) return p1.x < p2.x;
        return p1.y < p2.y;
    });
    int N=P.size(), k=0, t;
    vector<point<T>> res(N*2);
    for (int i=0; i<N; i++){
        while(k > 1 && crossp(res[k-2], res[k-1], res[k-1], P[i]) <= 0) k--;
        res[k] = P[i];
        k++;
    }
    t = k;
    for (int i=N-2; i>=0; i--){
        while(k > t && crossp(res[k-2], res[k-1], res[k-1], P[i]) <= 0) k--;
        res[k] = P[i];
        k++;
    }
    res.resize(k-1);
    return res;
}
int main(){
    vector<point<int>> P(5);
    for (auto &[x, y] : P) cin >> x >> y;
    cout << (convex_hull(P).size() == 5 ? "YES" : "NO") << endl;
    return 0;
}
            
            
            
        
            
srjywrdnprkt