結果

問題 No.199 星を描こう
ユーザー tnakao0123tnakao0123
提出日時 2016-03-27 02:40:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,162 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 85,412 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-28 18:45:32
合計ジャッジ時間 1,602 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 199.cc: No.199 星を描こう - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int N = 5;

/* typedef */

template <typename T>
struct Pt {
  T x, y;

  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt& pt) : x(pt.x), y(pt.y) {}

  bool operator==(const Pt pt) const { return x == pt.x && y == pt.y; }
  Pt<T> operator+(const Pt pt) const { return Pt<T>(x + pt.x, y + pt.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt pt) const { return Pt<T>(x - pt.x, y - pt.y); }
  Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
  Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
  T dot(Pt v) const { return x * v.x + y * v.y; }
  T cross(Pt v) const { return x * v.y - y * v.x; }
  Pt<T> mid(const Pt pt) { return Pt<T>((x + pt.x) / 2, (y + pt.y) / 2); }
  T d2() { return x * x + y * y; }
  double d() { return sqrt(d2()); }

  Pt<T> rot(double th) {
    double c = cos(th), s = sin(th);
    return Pt<T>(c * x - s * y, s * x + c * y);
  }

  Pt<T> rot90() { return Pt<T>(-y, x); }

  bool operator<(const Pt& pt) const {
    return x < pt.x || (x == pt.x && y < pt.y);
  }

  void print(string format) {
    printf(("(" + format + ", " + format + ")\n").c_str(), x, y);
  }
  void print() { print("%.6lf"); }
};

typedef Pt<double> pt;

struct CL {
  pt p;
  double t0, t1;
  CL() {}
  CL(const pt& _p, double _t0, double _t1) : p(_p), t0(_t0), t1(_t1) {}
};

/* global variables */

pt pts[N];
bool cm[N][N][N][N];
int pmis[N];

/* subroutines */

bool cross_lines(const pt& ap, const pt av, const pt& bp, const pt bv) {
  double op01 = av.cross(bv);
  if (op01 == 0.0) return false;

  pt v = bp - ap;
  double op0 = v.cross(av);
  double op1 = v.cross(bv);

  double t0 = op1 / op01;
  double t1 = op0 / op01;

  CL cl;
  cl.p = bv * t1 + bp;
  cl.t0 = t0;
  cl.t1 = t1;

  return (0.0 < cl.t0 && cl.t0 < 1.0 && 0.0 < cl.t1 && cl.t1 < 1.0);
}

/* main */

int main() {
  for (int i = 0; i < N; i++) cin >> pts[i].x >> pts[i].y;

  for (int i = 0; i < N; i++)
    for (int j = i + 1; j < N; j++) {
      pt vij = pts[j] - pts[i];
      for (int k = 0; k < N; k++)
	if (k != i && k != j)
	  for (int l = k + 1; l < N; l++)
	    if (l != i && l != j) {
	      pt vkl = pts[l] - pts[k];
	      if (cross_lines(pts[i], vij, pts[k], vkl))
		cm[i][j][k][l] = cm[j][i][k][l] = 
		  cm[i][j][l][k] = cm[j][i][l][k] = true;
	    }
    }

  for (int i = 0; i < N; i++) pmis[i] = i;

  do {
    bool ok = true;
    int is[N];
    for (int i = 0; ok && i < N; i++) {
      for (int j = 0; j < N; j++) is[j] = pmis[(i + j) % N];
      if (! cm[is[0]][is[1]][is[2]][is[3]] ||
	  ! cm[is[0]][is[1]][is[3]][is[4]]) ok = false;
    }

    if (ok) {
      puts("YES");
      return 0;
    }
  } while (next_permutation(pmis, pmis + N));

  puts("NO");
  return 0;
}
0