結果
| 問題 | No.199 星を描こう |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-26 17:13:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 4,519 bytes |
| コンパイル時間 | 1,453 ms |
| コンパイル使用メモリ | 137,964 KB |
| 最終ジャッジ日時 | 2025-01-19 04:38:02 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template<class T>
inline bool chmax(T& x, T y){
if(x < y){
x = y;
return true;
}
return false;
}
template<class T>
inline bool chmin(T& x, T y){
if(x > y){
x = y;
return true;
}
return false;
}
using ld = long double;
using Point = complex<ld>;
using Set = vector<Point>;
const ld pi = acos(-1);
constexpr ld eps = 1e-9;
constexpr ld inf = 1e12;
// 外積
ld cross(const Point& a, const Point& b){
return a.real() * b.imag() - a.imag() * b.real();
}
// 内積
ld dot(const Point& a, const Point& b){
return a.real() * b.real() + a.imag() * b.imag();
}
enum CCW_RESULT{
CCW = +1, CW = -1, BEHIND = +2, FRONT = -2, ON = 0
};
// b, c に対して、a がどの位置にあるか
int ccw(Point a, Point b, Point c){
b -= a, c -= a;
if(cross(b, c) > eps) return CCW; // 上側
if(cross(b, c) < -eps) return CW; // 下側
// cross(b, c) == 0
if(dot(b, c) < 0) return BEHIND; // 同一直線上の左側
if(norm(b) < norm(c)) return FRONT; // 同一直線上の右側
return ON; // 線分 ab 上にある
}
// 直線 (2つの点で表す)
struct Line : public vector<Point>{
Line(const Point& a = Point(), const Point& b = Point()) : vector<Point>(2){
begin()[0] = a;
begin()[1] = b;
}
// Ax + By + C = 0
Line(ld A, ld B, ld C){
if(abs(A) < eps && abs(B) < eps){
abort();
}
else if(abs(A) < eps){
*this = Line(Point(0, -C / B), Point(1, -C / B));
}
else if(abs(B) < eps){
*this = Line(Point(-C / A, 0), Point(-C / A, 1));
}
else{
*this = Line(Point(0, -C / B), Point(-C / A, 0));
}
}
};
/* 交差判定 */
// 直線と直線
bool intersectLL(const Line& l, const Line& m){
return abs(cross(l[1] - l[0], m[1] - m[0])) > eps || // 平行でない
abs(cross(l[1] - l[0], m[0] - l[0])) < eps; // 同じ直線
}
// 直線と線分
bool intersectLS(const Line &l, const Line& s){
// cross(l[1] - l[0], s[0] - l[0]) : s[0] が左側
// cross(l[1] - l[0], s[1] - l[0]) : s[1] が右側
return cross(l[1] - l[0], s[0] - l[0]) * cross(l[1] - l[0], s[1] - l[0]) < eps;
}
// 直線と点
bool intersectLP(const Line& l, const Point& p){
return abs(cross(l[1] - p, l[0] - p)) < eps;
}
// 線分と線分
bool intersectSS(const Line& s, const Line& t){
return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
// 線分と点
bool intersectSP(const Line& s, const Point& p){
// 三角不等式
return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
Set ps;
for(int i = 0; i < 5; ++i){
int x, y;
cin >> x >> y;
ps.emplace_back(x, y);
}
vector<int> perm(5);
for(int i = 0; i < 5; ++i) perm[i] = i;
do {
bool ok = true;
for(int i = 0; i < 5; ++i){
// r
// p q
// s t
int p = perm[i], q = perm[(i + 1) % 5];
int s = perm[(i + 2) % 5], r = perm[(i + 3) % 5], t = perm[(i + 4) % 5];
auto x = cross(ps[q] - ps[p], ps[r] - ps[p]);
auto y = cross(ps[q] - ps[p], ps[s] - ps[p]);
if(x * y >= 0 || !intersectSS(Line(ps[p], ps[q]), Line(ps[r], ps[s]))){
ok = false;
}
y = cross(ps[q] - ps[p], ps[t] - ps[p]);
if(x * y >= 0 || !intersectSS(Line(ps[p], ps[q]), Line(ps[r], ps[t]))){
ok = false;
}
}
if(ok){
cout << "YES\n";
return 0;
}
} while(next_permutation(begin(perm), end(perm)));
cout << "NO\n";
return 0;
}