結果
| 問題 |
No.3005 トレミーの問題
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-01-22 10:25:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 2,618 bytes |
| コンパイル時間 | 398 ms |
| コンパイル使用メモリ | 43,136 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-01-22 10:25:05 |
| 合計ジャッジ時間 | 2,046 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘void readpt(pt&)’:
main.cpp:89:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
89 | void readpt(pt &a) { scanf("%lf%lf", &a.x, &a.y); }
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 3005.cc: No.3005 繝医Ξ繝溘・縺ョ蝠城。・- yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const double DELTA = 1e-8;
/* 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; }
double d() { return sqrt(d2()); }
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);
}
};
using pt = Pt<double>;
struct CL {
pt p;
double t0, t1;
CL() {}
CL(const pt& _p, double _t0, double _t1) : p(_p), t0(_t0), t1(_t1) {}
};
/* global variables */
/* 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);
}
void readpt(pt &a) { scanf("%lf%lf", &a.x, &a.y); }
/* main */
int main() {
pt a, b, c, d;
readpt(a), readpt(b), readpt(c), readpt(d);
pt v0(b - a), v1(c - a);
if (v0.cross(v1) == 0.0) { puts("NO"); return 0; }
pt p0 = v0 * 0.5 + a, p1 = v1 * 0.5 + a;
pt nv0 = v0.rot90(), nv1 = v1.rot90();
CL cl;
cross_lines(p0, nv0, p1, nv1, cl);
//printf(" %lf,%lf\n", cl.p.x, cl.p.y);
double rr0 = (a - cl.p).d2(), rr1 = (d - cl.p).d2();
if (abs(rr1 - rr0) < DELTA) puts("YES");
else puts("NO");
return 0;
}
tnakao0123