QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624137 | #7065. Triangle | bright_ml# | AC ✓ | 1850ms | 4052kb | C++20 | 4.9kb | 2024-10-09 15:03:44 | 2024-10-09 15:03:44 |
Judging History
answer
//
// Created by 35395 on 2024/10/9.
//
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
using db = double;
const db eps = 1e-9;
int sgn(db x) {
if(fabs(x) < eps) return 0;
if(x < 0) return -1;
return 1;
}
struct Point {
db x, y;
Point () {
x = y = 0;
}
Point (db _x, db _y) {
x = _x, y = _y;
}
void input() {
cin >> x >> y;
}
friend inline Point operator-(Point A, Point B) {
return Point(A.x - B.x, A.y - B.y);
}
friend inline Point operator+(Point A, Point B) {
return Point(A.x + B.x, A.y + B.y);
}
friend inline Point operator/(Point A, int t) {
return Point(A.x / t, A.y / t);
}
friend inline db operator*(Point A, Point B) {
return A.x * B.x + A.y * B.y;
}
friend inline db operator^(Point A, Point B) {
return A.x * B.y - A.y * B.x;
}
};
struct Line {
Point s, e;
Line () {}
Line (Point _s, Point _e) {
s = _s;
e = _e;
}
void input() {
s.input();
e.input();
}
bool PointOnSegment(Point p) {
return sgn((p - s) ^ (e - s)) == 0 && sgn((p - s) * (p - e)) <= 0;
}
};
struct Polygon {
int n;
vector<Point> p;
vector<Line> l;
Polygon () {
n = 0;
p.clear();
l.clear();
}
void input() {
n = 3;
p.resize(n);
l.resize(n);
for(int i = 0; i < n; i++) {
p[i].input();
}
for(int i = 0; i < n; i++) {
l[i] = Line(p[i], p[(i + 1) % n]);
}
}
db area() {
db ans = 0;
for(int i = 2; i < n; i++) {
ans += (p[i] - p[0]) ^ (p[i - 1] - p[0]);
}
return fabs(ans) / 2;
}
};
db area(Point a, Point b, Point c) {
db ans = 0;
ans += (c - a) ^ (b - a);
ans /= 2;
return fabs(ans);
}
void solve() {
Polygon poly;
poly.input();
Point p;
p.input();
int cnt = 0;
Line l1, l2;
for(auto l: poly.l) {
if(l.PointOnSegment(p)) {
cnt++;
l1 = l;
} else {
l2 = l;
}
}
if(cnt == 0) {
cout << "-1\n";
return;
}
if(cnt == 2) {
for(auto l: poly.l) {
if(!l.PointOnSegment(p)) {
Point x = (l.s + l.e) / 2;
cout << x.x << ' ' << x.y << '\n';
return;
}
}
}
int idx, g;
for(int i = 0; i < 3; i++) {
if(!l1.PointOnSegment(poly.p[i])) {
idx = i;
break;
}
}
db mj = poly.area() / 2;
if(area(poly.p[idx], poly.p[(idx + 1) % 3], p) < mj) {
g = (idx - 1 + 3) % 3;
} else {
g = (idx + 1) % 3;
}
if(poly.p[g].x != poly.p[idx].x) {
bool flag = false;
if(poly.p[g].x > poly.p[idx].x) {
flag = true;
}
db l = min(poly.p[g].x, poly.p[idx].x), r = max(poly.p[g].x, poly.p[idx].x);
Point ans;
while(r - l > eps) {
db mid = (l + r) / 2;
Point o;
o.x = mid;
o.y = poly.p[g].y - (poly.p[g].y - poly.p[idx].y) * (poly.p[g].x - mid) / (poly.p[g].x - poly.p[idx].x);
ans = o;
if(sgn(area(o, p, poly.p[g]) - mj) >= 0) {
if(flag) {
l = mid;
} else {
r = mid;
}
} else {
if(flag) {
r = mid;
} else {
l = mid;
}
}
}
cout << ans.x << ' ' << ans.y << '\n';
} else {
bool flag = false;
if(poly.p[g].y > poly.p[idx].y) {
flag = true;
}
db l = min(poly.p[g].y, poly.p[idx].y), r = max(poly.p[g].y, poly.p[idx].y);
Point ans;
while(r - l > eps) {
db mid = (l + r) / 2;
Point o;
o.y = mid;
o.x = poly.p[g].x - (poly.p[g].x - poly.p[idx].x) * (poly.p[g].y - mid) / (poly.p[g].y - poly.p[idx].y);
ans = o;
if(sgn(area(o, p, poly.p[g]) - mj) >= 0) {
if(flag) {
l = mid;
} else {
r = mid;
}
} else {
if(flag) {
r = mid;
} else {
l = mid;
}
}
}
cout << ans.x << ' ' << ans.y << '\n';
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while(T--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3816kb
input:
2 0 0 1 1 1 0 1 0 0 0 1 1 1 0 2 0
output:
0.5000000000 0.5000000000 -1
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 1069ms
memory: 3984kb
input:
999966 9456 15557 18451 3957 6242 20372 9855 5351 30245 31547 9979 4703 25914 19144 26670 11383 13855 0 24614 0 15860 11017 12445 0 27870 17680 4219 3554 9129 29072 28316 17893 3249 27269 12754 4923 31746 16860 14894 21576 6846 0 1915 0 25023 28721 10508 0 10110 11862 23224 10373 17715 8212 29474 11...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 21424.6814794172 13086.0539109838 -1 -1 18711.2379903044 10162.3763772596 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 28212.9521348918 245.8177862387 -1 -1 -1 -1 -1 -1 -1 -1 22604.5753021893 14546.1287161064 -1 -1 11557.3465218994 46...
result:
ok 1111378 numbers
Test #3:
score: 0
Accepted
time: 1093ms
memory: 3884kb
input:
999974 9228 16833 13143 23461 5117 7645 21359 13652 21313 3160 20333 1620 16288 7781 13315 10132 4372 0 27536 0 3207 8695 9983 0 21469 29998 19948 29904 30517 11141 14857 12881 11116 29172 16833 32095 18915 9448 22043 12275 32131 0 14304 0 16638 29018 2048 0 4695 4823 14130 2496 32676 4092 6363 2476...
output:
-1 -1 11482.9903720156 5737.2238363814 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 15409.8418549340 12451.4278636549 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 10828.9713857793 25347.3348573222 -1 -1 -1 -1 -1 18768.6726994652 12151.3671509895 -1 -1 -1 -1 -1 10801.120...
result:
ok 1110866 numbers
Test #4:
score: 0
Accepted
time: 1850ms
memory: 4052kb
input:
1000000 54242 34392 23333 92971 5711 47765 54242 34392 24492 41078 36756 68794 2060 62118 14678 50283 12685 18891 59613 23256 26016 46755 59613 23256 85238 49611 95092 85360 45143 87657 95092 85360 72852 37174 39825 60628 32289 18423 72852 37174 95309 61613 1645 45877 78395 38196 95309 61613 92215 7...
output:
14522.0000000000 70368.0000000000 32900.8888888888 68052.2222222222 19350.5000000000 32823.0000000000 65190.5000000000 68634.0000000000 36057.0000000000 39525.5000000000 40020.0000000000 42036.5000000000 95183.4999999991 40970.4999999897 28582.0000000000 94834.5000000000 55598.0000000000 59174.00000...
result:
ok 2000000 numbers