You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.7 KiB
C++
106 lines
3.7 KiB
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
#define CRP(t, x) const t &x
|
|
#define OPX(op, t, x) operator op(CRP(t, x))
|
|
#define OPL(t, x) bool OPX(<, t, x) const
|
|
#define FIL(x, v) memset(x, v, sizeof(x))
|
|
#define CLR(x) FIL(x, 0)
|
|
#define NE1(x) FIL(x, -1)
|
|
#define INF(x) FIL(x, 0x3f)
|
|
#ifndef _DEBUG
|
|
#define _DEBUG 0
|
|
#endif // !_DEBUG
|
|
#define IFD if (_DEBUG)
|
|
typedef long long ll, i64;
|
|
|
|
constexpr double eps = 1e-8;
|
|
int sgn(double x)
|
|
{
|
|
if (x > eps)
|
|
return 1;
|
|
if (x < -eps)
|
|
return -1;
|
|
return 0;
|
|
}
|
|
template <typename T>
|
|
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
|
template <typename T>
|
|
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
|
template <typename T, typename = enable_if_arithmetic<T>>
|
|
struct Point
|
|
{
|
|
T x, y;
|
|
Point OPX(-, Point, rhs) const { return {x - rhs.x, y - rhs.y}; }
|
|
T OPX(*, Point, rhs) const { return x * rhs.x + y * rhs.y; }
|
|
T OPX (^, Point, rhs) const { return x * rhs.y - y * rhs.x; }
|
|
T len2() const { return x * x + y * y; }
|
|
double len() const { return sqrt(len2()); }
|
|
};
|
|
template <typename T>
|
|
struct Line
|
|
{
|
|
Point<T> s, e;
|
|
T len2() const { return (s - e).len2(); }
|
|
double len() const { return (s - e).len(); }
|
|
bool contains(CRP(Point<T>, p)) const { return sgn((s - p) ^ (e - p)) == 0 && sgn((s - p) * (e - p)) <= 0; }
|
|
};
|
|
#define Point Point<double>
|
|
#define Line Line<double>
|
|
double area(CRP(Point, p1), CRP(Point, p2), CRP(Point, p3))
|
|
{
|
|
return abs((p3 - p1) ^ (p2 - p1));
|
|
}
|
|
int main2()
|
|
{
|
|
Point p[3], e;
|
|
while (~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &p[0].x, &p[0].y, &p[1].x, &p[1].y, &p[2].x, &p[2].y, &e.x, &e.y))
|
|
{
|
|
Line ls[3] = {{p[1], p[2]}, {p[0], p[2]}, {p[0], p[1]}};
|
|
bool flag = true;
|
|
for (int i = 0; i < 3 && flag; i++)
|
|
if (ls[i].contains(e))
|
|
{
|
|
int l = (i + 2) % 3, r = (i + 1) % 3;
|
|
int near = (e - p[l]).len2() < (e - p[r]).len2() ? l : r;
|
|
int other = l + r - near;
|
|
double len = ls[i].len() * ls[near].len() / 2 / (e - p[other]).len();
|
|
double fulllen = ls[near].len();
|
|
Point dif = p[i] - p[other];
|
|
printf("%.12lf %.12lf\n", p[other].x + dif.x * len / fulllen, p[other].y + dif.y * len / fulllen);
|
|
if (sgn(area(p[other], e, {p[other].x + dif.x * len / fulllen, p[other].y + dif.y * len / fulllen}) * 2 - area(p[0], p[1], p[2])))
|
|
return -1;
|
|
flag = false;
|
|
}
|
|
if (flag)
|
|
puts("-1");
|
|
}
|
|
return 0;
|
|
}
|
|
int main()
|
|
{
|
|
Point p[3], e;
|
|
while (~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &p[0].x, &p[0].y, &p[1].x, &p[1].y, &p[2].x, &p[2].y, &e.x, &e.y))
|
|
{
|
|
Line ls[3] = {{p[1], p[2]}, {p[0], p[2]}, {p[0], p[1]}};
|
|
bool flag = true;
|
|
for (int i = 0; i < 3 && flag; i++)
|
|
if (ls[i].contains(e))
|
|
{
|
|
int l = (i + 2) % 3, r = (i + 1) % 3;
|
|
int near = (e - p[l]).len2() < (e - p[r]).len2() ? l : r;
|
|
int other = l + r - near;
|
|
double len = sqrt(ls[i].len2() * ls[near].len2() / 4 / (e - p[other]).len2());
|
|
double fulllen = ls[near].len();
|
|
Point dif = p[i] - p[other];
|
|
printf("%.12lf %.12lf\n", p[other].x + dif.x * len / fulllen, p[other].y + dif.y * len / fulllen);
|
|
if (sgn(area(p[other], e, {p[other].x + dif.x * len / fulllen, p[other].y + dif.y * len / fulllen}) * 2 - area(p[0], p[1], p[2])))
|
|
return -1;
|
|
flag = false;
|
|
}
|
|
if (flag)
|
|
puts("-1");
|
|
}
|
|
return 0;
|
|
} |