예제 #1
0
파일: e.cpp 프로젝트: ifsmirnov/olymp
ld mtime(pt u, pt v, ld t, pt s) {
#define DD(x) (s.d2(u+v*(t+(x))))
#define OK(x) (DD(x) <= v2 * (x) * (x))

    u.x -= s.x;
    u.y -= s.y;

    s = pt(0, 0);

    const ld v2 = ::v*::v;

    if (OK(0)) {
        return t;
    }

    u = u + v*t;

    ld A = v.d2() - v2;
    ld B = 2.0 * (u.x * v.x + u.y * v.y);
    ld C = u.d2();

    ld D = B*B - 4.0 * A * C;
    D = sqrtl(max(D, 0.0l));

    return t + (-B-D) / (2*A);
// 
//     ld t1 = (-B + D) / (2*A);
//     ld t2 = (-B - D) / (2*A);
// 
// //     cout << t1 << " " << t2 << endl;
//     assert(t1 >= 0 || t2 >= 0);
//     if (t1 > t2) swap(t1, t2);
//     return t + (t1 >= 0 ? t1 : t2);
}
예제 #2
0
main()
{
    P.scan() ; scanf("%d",&n) ;
    for(int i=0;i<n;i++) a[i].scan() ;
    Q.scan() ; scanf("%d",&m) ;
    for(int i=0;i<m;i++) b[i].scan() ;
    for(int i=0;i<n;i++) for(int j=0;j<m;j++)
        if(check(a[i],a[(i+1)%n],b[j])){printf("YES\n") ; return 0 ;}
    swap(n,m) ; swap(P,Q) ; swap(a,b) ;
    for(int i=0;i<n;i++) for(int j=0;j<m;j++)
        if(check(a[i],a[(i+1)%n],b[j])){printf("YES\n") ; return 0 ;}
    printf("NO\n") ;
}
 pair<pt, bool> _nn(
         const pt &p, node *n, bb b, double &mn, int c, bool same) {
     if (!n || b.dist(p) > mn) return make_pair(pt(), false);
     bool found = same || p.dist(n->p) > EPS, l1 = true, l2 = false;
     pt resp = n->p;
     if (found) mn = min(mn, p.dist(resp));
     node *n1 = n->l, *n2 = n->r;
     for (int i = 0; i < 2; i++) {
         if (i == 1 || cmp(c)(n->p, p)) swap(n1, n2), swap(l1, l2);
         pair<pt, bool> res =
             _nn(p, n1, b.bound(n->p.coord[c], c, l1), mn, INC(c), same);
         if (res.second && (!found || p.dist(res.first) < p.dist(resp)))
             resp = res.first, found = true;
     }
     return make_pair(resp, found); } };
// returns 0-2 _unique_ points.
// res[0] lies on the left side of line (a-->b)
vector<pt> cross(const pt &a, double r1, pt b,
                 double r2) {
  b = b - a;
  if (fabs(b.dist2()) < eps) {
    if (fabs(r1) < eps && fabs(r2) < eps)
      return vector<pt>(1, a);

    assert(fabs(r1 - r2) > eps);
    return vector<pt>();
  }
  vector<pt> res = cross(b, r2,
      line(2 * b.x, 2 * b.y,
           sqr(r2) - sqr(r1) -
           sqr(b.x) - sqr(b.y)));
  for (int i = 0; i < sz(res); i++)
    res[i] = res[i] + a;
  return res;
}
예제 #5
0
void update(pt & cur, int query_l, int query_r)
{
	if (cur->l == query_l && cur->r == query_r)
	{
		cur->delta++;
		return;
	}
	int m = cur->get_m();
	if (query_l < m && useful(query_l, min(query_r, m)))
	{
		if (cur->left == NULL)
			cur->left = new node(cur->l, m);
		update(cur->left, query_l, min(query_r, m));
	}
	if (query_r > m && useful(max(query_l, m), query_r))
	{
		if (cur->right == NULL)
			cur->right = new node(m, cur->r);
		update(cur->right, max(query_l, m), query_r);
	}
}
예제 #6
0
    pt geodesique(pt p, std::ostream *os = nullptr) const {
        std::set<pt> S;
        while (true) {
            if (!fits(vb::coo{p.xi(), p.yi()})) { break; }
            if (os != nullptr) { (*os) << p; }
            p.step(*this);
            if (S.count(p) != 0) { break; }
            S.insert(p);
        }
        if (os != nullptr) { (*os) << std::endl; }

        if (!fits(vb::coo{p.xi(), p.yi()})) { return pt(); }

        pt p_min = p;
        p.step(*this);
        while (p != p_min) {
            if (p < p_min) { p_min = p; }
            p.step(*this);
        }

        return p_min;
    }
예제 #7
0
bool seg_intersect(pt p, pt q, pt r, pt s) {
    if(r.between(p, q) || s.between(p, q) || p.between(r, s) || q.between(r, s)) return true;
    pt a = line_intersect(p, q, r, s);
    return a.between(p, q) && a.between(r, s);
}
예제 #8
0
     [[nodiscard]] double dist2(const pt &o) const {
     double dx = x() - o.x(), dy = y() - o.y();
     return dx * dx + dy * dy;
 }
예제 #9
0
 std::pair<pt, pt> leaf(pt p, std::ostream *os = nullptr) const {
     pt p1 = geodesique(p, os);
     p.reverse();
     pt p2 = geodesique(p, os);
     return (p1 < p2) ? ptpair{p1, p2} : ptpair{p2, p1};
 }
예제 #10
0
파일: h.cpp 프로젝트: Rasinhas/Maratona
//retorna true se o angulo pqr eh maior que PI e false cc
bool large_angle(pt p, pt q, pt r) { return q.right(p, r); }
예제 #11
0
bool rcmp(pt a, pt b) {
  a = a - _root; b = b - _root;
  int s = a * b;
  if (s) return s > 0;
  return a.dist2() < b.dist2();
}