結果

問題 No.199 星を描こう
ユーザー airisairis
提出日時 2015-05-30 13:24:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,547 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 84,808 KB
実行使用メモリ 4,484 KB
最終ジャッジ日時 2023-08-28 18:39:30
合計ジャッジ時間 1,850 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#include <bitset>
#include <complex>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)
#define EPS (1e-14)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;

struct P {
	double x, y;
	P() : x(0), y(0) {}
	P(double x, double y) : x(x), y(y) {};
	// 誤差を考慮して加算
	double add(double a, double b) {
		if (abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
		return a + b;
	}
	P operator+(P p) {
		return P(add(x, p.x), add(y, p.y));
	}
	P operator-(P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator*(double d) {
		return P(x * d, y * d);
	}
	double dot(P p) { // 内積
		return add(x * p.x, y * p.y);
	}
	double cross(P p) { // 外積
		return add(x * p.y, -y * p.x);
	}
};
bool intersect(P s1, P e1, P s2, P e2) { // 線分交差
	//x座標的に離れて位置している
	if (max(s1.x, e1.x) < min(s2.x, e2.x) || max(s2.x, e2.x) < min(s1.x, e1.x)) return false;
	//y座標的に離れて位置している
	if (max(s1.y, e1.y) < min(s2.y, e2.y) || max(s2.y, e2.y) < min(s1.y, e1.y)) return false;
	//交差している
	double res1 = (e1 - s1).cross(s2 - s1) * (e1 - s1).cross(e2 - s1);
	double res2 = (e2 - s2).cross(e1 - s2) * (e2 - s2).cross(s1 - s2);
	return (res1 < EPS) && (res2 < EPS);
}
bool on_seg(P p1, P p2, P q) { // 線分p1-p2上にある点qがあるか判定
	return (p1 - q).cross(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}


int N;
// グラハムスキャンによる凸包
P ps[50005];

bool cmp_x(const P &s, const P &t) {
	if (s.x != t.x) return s.x < t.x;
	return s.y < t.y;
}
vector<P> convex_hull(P *ps, int n) {
	sort(ps, ps + n, cmp_x);
	int k = 0;
	vector<P> qs(n * 2);
	for (int i = 0; i < n; i++) {
		while (k > 1 && (qs[k-1] - qs[k-2]).cross(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]).cross(ps[i] - qs[k-1]) <= 0) k--;
		qs[k++] = ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int main() {
	rep(i, 5) {
		cin >> ps[i].x >> ps[i].y;
	}
	vector<P> qs = convex_hull(ps, 5);
	if (qs.size() == 5) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


0