結果

問題 No.2602 Real Collider
ユーザー tnakao0123tnakao0123
提出日時 2024-01-14 02:21:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,532 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 44,928 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-28 01:55:51
合計ジャッジ時間 4,819 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 59 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2602.cc:  No.2602 Real Collider - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const double DELTA = 1e-7;

/* typedef */

template <typename T>
struct Pt {
  T x, y;
  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt<T> &p) : x(p.x), y(p.y) {}

  Pt<T> operator+(const Pt<T> p) const { return Pt<T>(x + p.x, y + p.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt<T> p) const { return Pt<T>(x - p.x, y - p.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<T> v) const { return x * v.x + y * v.y; }
  T cross(Pt<T> v) const { return x * v.y - y * v.x; }
  Pt<T> mid(const Pt<T> p) { return Pt<T>((x + p.x) / 2, (y + p.y) / 2); }
  T d2() { return x * x + y * y; }

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

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

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 readpt() {
  int x, y;
  scanf("%d%d", &x, &y);
  return pt(x, y);
}

/* subroutines */

bool cross_lines(const pt& ap, const pt av, const pt& bp, const pt bv, CL& cl) {
  double op01 = av.cross(bv);
  //if (op01 == 0.0) return false; /* need to handle parallel?? */

  if (op01 == 0.0) {
    pt v = bp - ap;
    if (v.cross(av) != 0.0) return false;

    pt a1 = ap + av;
    pt b1 = bp + bv;

    return
      ((bp - ap).dot(b1 - ap) <= 0.0 ||
       (bp - a1).dot(b1 - a1) <= 0.0 ||
       (ap - bp).dot(a1 - bp) <= 0.0 ||
       (ap - b1).dot(a1 - b1) <= 0.0);
  }

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

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

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

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

/* main */

int main() {
  int qn;
  scanf("%d", &qn);
  pt pa = readpt(), pb = readpt(), pc = readpt();

  pt p0 = (pa + pb) / 2, p1 = (pa + pc) / 2;
  pt v0 = (pb - pa).rot90(), v1 = (pc - pa).rot90();
  CL cl;

  cross_lines(p0, v0, p1, v1, cl);
  pt cp = cl.p;
  double rr = (pa - cp).d2();

  while (qn--) {
    pt pi = readpt();
    if ((pi - cp).d2() <= rr + DELTA) puts("Yes");
    else puts("No");
  }

  return 0;
}
0