QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#593969 | #8779. Square of Triangles | betterer | WA | 653ms | 6068kb | C++20 | 8.9kb | 2024-09-27 17:39:13 | 2024-09-27 17:39:13 |
Judging History
answer
#ifndef ONLINE_JUDGE
// #define ONLINE_JUDGE
#endif
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ull = unsigned long long;
#ifdef ONLINE_JUDGE
#define des(...)
#define de(...)
#else
#define des(x) cerr<<(x)<<endl
#endif
struct point {
double x, y;
bool operator<(const point& p) const {
return x < p.x || (x == p.x && y < p.y);
}
point operator-(const point& p) const {
return {x - p.x, y - p.y};
}
point operator+(const point& p) const {
return {x + p.x, y + p.y};
}
double operator*(const point& p) const {
return x * p.y - y * p.x;
}
[[nodiscard]] point complex_mul(const point& p) const {
return {x * p.x - y * p.y, x * p.y + y * p.x};
}
[[nodiscard]] point complex_div(const point& p) const {
return {x * p.x + y * p.y, y * p.x - x * p.y};
}
point operator*(const double v) const {
return {x * v, y * v};
}
point operator/(const double v) const {
return {x / v, y / v};
}
[[nodiscard]] double hypot() const {
return ::hypot(x, y);
}
[[nodiscard]] point unit() const {
return *this / hypot();
}
[[nodiscard]] double dot(const point& p) const {
return x * p.x + y * p.y;
}
#ifndef ONLINE_JUDGE
void print() const {
::print(make_pair(x, y));
}
#endif
};
struct line {
point p1, p2;
[[nodiscard]] bool separate(const point& q1, const point& q2) const {
double t1 = (q1 - p1) * (p2 - p1), t2 = (q2 - p1) * (p2 - p1);
return abs(t1) > 1e-6 && abs(t2) > 1e-6 && t1 * t2 < 0;
}
[[nodiscard]] bool intersect(const line& l) const {
return separate(l.p1, l.p2) && l.separate(p1, p2);
}
};
struct triangle {
vector<point> ps;
static triangle from_edge(double x, double y, double z) {
triangle ret;
ret.ps.emplace_back(0, 0);
ret.ps.emplace_back(sqrt(x), 0);
double cos_angle = (x + y - z) / (2 * sqrt(x * y));
ret.ps.emplace_back(sqrt(y) * cos_angle, sqrt(y) * sqrt(1 - cos_angle * cos_angle));
return ret;
}
[[nodiscard]] double size() const {
return abs((ps[1] - ps[0]) * (ps[2] - ps[0])) / 2;
}
[[nodiscard]] bool intersect(const triangle& t) const {
for (int i = 0; i < ps.size(); ++i) {
for (int j = 0; j < t.ps.size(); ++j) {
if (line{ps[i], ps[(i + 1) % ps.size()]}.intersect({t.ps[j], t.ps[(j + 1) % t.ps.size()]}))return true;
}
}
return false;
}
#ifndef ONLINE_JUDGE
void print() const {
::print(ps);
}
#endif
};
double area;
struct many_triangle {
vector<triangle> ts;
[[nodiscard]] vector<many_triangle> combine_with(const triangle& tri) const {
vector<many_triangle> ret;
for (auto& t : ts) {
vector<int> perm(3);
iota(perm.begin(), perm.end(), 0);
do {
auto vec1 = t.ps[perm[1]] - t.ps[perm[0]];
auto vec2 = t.ps[perm[2]] - t.ps[perm[0]];
auto angle = vec1 * vec2 > 0 ? vec1.unit().complex_div(tri.ps[2].unit()).unit() : vec1.unit();
auto pos = t.ps[perm[0]];
auto tri2 = tri;
for (auto& p : tri2.ps)p = p.complex_mul(angle) + pos;
// 剪枝,去掉过远点
for (auto& p : tri2.ps) {
for (auto& t2 : ts) {
for (auto& p2 : t2.ps) {
if ((p - p2).hypot() > sqrt(area * 2) * (1 + .01)) {
goto end;
}
}
}
}
for (auto& t2 : ts) {
if (t2.intersect(tri2)) {
goto end;
}
}
{
many_triangle rt = *this;
rt.ts.push_back(tri2);
ret.push_back(rt);
}
end:;
} while (ranges::next_permutation(perm).found);
}
return ret;
}
[[nodiscard]] bool check() const {
vector<point> vp;
for (auto& t : ts)for (auto& p : t.ps)vp.push_back(p);
// 求凸包
sort(vp.begin(), vp.end());
sort(vp.begin() + 1, vp.end(), [&](const point& u, const point& v) {
auto t = (u - vp[0]) * (v - vp[0]);
if (t)return t > 0;
return u < v;
});
vector<point> sta;
sta.push_back(vp[0]);
for (int i = 1; i < vp.size(); ++i) {
while (sta.size() >= 2 && (sta.back() - sta[sta.size() - 2]) * (vp[i] - sta.back()) <= 1e-6) {
sta.pop_back();
}
sta.push_back(vp[i]);
}
// sta.push_back(vp[0]); //sta+1
// if (sta.size() != 4) {
// // de(*this);
// // des("not 4 edges");
// return false;
// }
double s = 0, c = 0;
for (int i = 1; i < sta.size(); ++i) {
s += (sta[i - 1] - sta[0]) * (sta[i] - sta[0]) / 2;
}
vector<double> edges;
for (int i = 0; i < sta.size(); ++i) {
edges.push_back((sta[i] - sta[(i + 1) % sta.size()]).hypot());
c += edges.back();
}
if (abs(s / area - 1) > 1e-6) {
// des("not same area");
// de(ans, area);
return false;
}
if (abs(c / (4 * sqrt(area)) - 1) > 1e-6) {
return false;
}
de(*this);
de(s, area, c, 4 * sqrt(area), sta);
// ranges::sort(edges);
// while (edges.front() < 1e-6) edges.erase(edges.begin());
// de(edges.size(), edges);
// if (edges.size() != 4) {
// des("not 4 edges");
// return false;
// }
// if (abs(edges.front() - edges.back()) > 1e-6) {
// des("not equal edges");
// // de(edges);
// return false;
// }
return true;
if (abs((sta[0] - sta[1]).hypot() - (sta[1] - sta[2]).hypot()) > 1e-6) {
des("not perpendicular");
return false;
}
if (abs((sta[0] - sta[2]).dot((sta[1] - sta[3]))) > 1e-6) {
// des("not square");
return false;
}
// de(edges);
return true;
}
#ifndef ONLINE_JUDGE
void print() const {
::print(ts);
}
#endif
};
struct triangle_order {
vector<double> v;
int id;
bool operator<(const triangle_order& t) const {
return v < t.v;
}
};
int T;
vector<double> a(3);
signed main() {
bool output = false;
cin.tie(nullptr)->sync_with_stdio(false);
cin >> T;
int div = 0;
while (T--) {
area = 0;
vector<vector<triangle>> vvt;
vector<triangle_order> vto;
for (int i = 0; i < 4; ++i) {
for (auto& j : a) {
int x;
cin >> x;
if (div == 0) {
div = 1;
while (x > div * 1000) div *= 10;
}
j = x;
j /= div;
if (T == 19 && i == 0 && x == 2352936)output = true;
}
if (output && T <= 20 - 5) {
for (auto& j : a)cout << j << ' ';
continue;
}
vvt.emplace_back();
ranges::sort(a);
if (i)vto.push_back({a, i});
do {
vvt.back().push_back(triangle::from_edge(a[0], a[1], a[2]));
} while (ranges::next_permutation(a).found);
area += vvt.back().back().size();
}
if (output) {
cout << endl;
continue;
}
for (int i = 0; i < 4; ++i) {
de(i, vvt[i].size(), vvt[i]);
}
// exit(0);
sort(vto.begin(), vto.end());
do {
vector<many_triangle> vmt, vmt2;
vmt.push_back({{vvt[0][0]}});
for (int i = 1; i < 4; ++i) {
for (auto& mt : vmt) {
for (auto& t : vvt[vto[i - 1].id]) {
auto res = mt.combine_with(t);
vmt2.insert(vmt2.end(), res.begin(), res.end());
}
}
vmt = move(vmt2);
}
for (auto& mt : vmt) {
if (mt.check()) {
cout << 1 << endl;
goto end;
}
}
} while (next_permutation(vto.begin(), vto.end()));
// de(vmt);
cout << 0 << endl;
end:;
// exit(0);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 27ms
memory: 4124kb
input:
3 1 1 2 2 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 5 125 130 125 20 145 45 130 145 145 145 80
output:
1 0 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 272ms
memory: 3964kb
input:
20 1998001 7984010 9982009 1998001 7984010 1994005 7984010 9978013 9982009 9978013 1994005 7984010 9958045 7968034 9962037 7968034 1994005 9962037 9958045 1990013 7968034 1994005 1990013 7968034 7952074 9938097 1986025 7952074 9942085 1990013 7952074 9942085 9938097 1986025 7952074 1990013 7936130 9...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok 20 lines
Test #3:
score: 0
Accepted
time: 372ms
memory: 4480kb
input:
20 1148639 3581051 1216206 9999916 7026968 270268 6013463 6013463 6756700 6013463 6013463 6756700 2608850 8630930 9445800 9862940 6448880 6939290 8631650 3682160 5184310 7504700 6652150 1917140 2359505 3170711 2299108 4027811 6760781 2960240 4679918 6106006 3178400 8153446 7975057 5222088 8849500 88...
output:
0 0 0 1 1 1 1 0 1 1 1 1 1 0 0 0 0 1 1 1
result:
ok 20 lines
Test #4:
score: 0
Accepted
time: 653ms
memory: 4476kb
input:
20 7300000 8100000 10000000 8100000 7300000 1000000 1000000 7300000 2900000 2900000 10000000 7300000 61728 8950560 9999936 7901184 4012320 4999968 8950560 3950592 4999968 4012320 123456 4999968 4494200 9932182 9932182 8381683 112355 9932182 5505395 9460291 9932182 9999595 4494200 9190639 5994936 671...
output:
1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 1 0 0
result:
ok 20 lines
Test #5:
score: 0
Accepted
time: 509ms
memory: 4508kb
input:
20 10000000 5078125 3828125 78125 5000000 5078125 1250000 10000000 6250000 5000000 6250000 1250000 7079600 5663680 1415920 7079600 796455 9999935 5663680 9999935 5752175 5663680 88495 5752175 4410468 1135368 9999972 5676840 4541472 5676840 4541472 5676840 5676840 8078580 742356 6288192 8345560 44707...
output:
1 1 0 0 0 1 1 1 1 1 1 0 0 1 0 1 0 1 0 0
result:
ok 20 lines
Test #6:
score: 0
Accepted
time: 605ms
memory: 4580kb
input:
20 10000000 5078125 3828125 2031250 78125 1953125 703125 5078125 2031250 5000000 10000000 5000000 5000000 10000000 5000000 5000000 2890625 390625 6250000 1250000 10000000 1250000 2890625 3515625 6711400 9999986 3288586 4899322 4295296 604026 6979856 9999986 4899322 6711400 6979856 268456 9767552 645...
output:
1 1 1 0 1 1 0 1 1 0 1 1 0 0 1 0 0 1 0 0
result:
ok 20 lines
Test #7:
score: 0
Accepted
time: 574ms
memory: 4472kb
input:
20 3063559 8439238 9999919 3063559 9999919 3005756 8381435 9999919 8439238 8381435 3005756 9999919 6923007 4319483 4852022 2130156 4319483 769223 9999899 3076892 6923007 6923007 2899379 4852022 3271584 4999968 493824 6049344 61728 5246880 4999968 4999968 9999936 5246880 3271584 3950592 7398784 99999...
output:
1 1 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 1 0 0
result:
ok 20 lines
Test #8:
score: 0
Accepted
time: 578ms
memory: 6068kb
input:
20 5524800 4475088 9999888 55248 4475088 4530336 9999888 5580048 5524800 55248 4530336 5580048 7123920 8940020 2698748 6206580 7677584 8296048 6252164 6473284 9023920 7524124 4702788 5944204 7901120 7901120 6320896 6320896 7901120 7901120 9135670 9999855 913567 1506151 1111095 98764 2222220 3555552 ...
output:
1 0 0 1 0 1 1 0 0 1 1 1 1 1 0 1 0 0 1 0
result:
ok 20 lines
Test #9:
score: 0
Accepted
time: 451ms
memory: 4660kb
input:
20 3404348 6811514 5073762 1575108 4047618 3481696 6589302 6594868 4559458 5124278 2664770 3517574 5393960 2157584 5393960 5393960 2157584 5393960 2199076 9999572 2821456 2157584 8972645 8723693 2091488 4248335 9999927 9999927 9542414 7385567 4248335 9542414 9999927 9999927 2091488 7385567 5867350 7...
output:
0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1
result:
ok 20 lines
Test #10:
score: 0
Accepted
time: 465ms
memory: 4908kb
input:
20 4753532 8244880 6269438 3937444 762818 4555348 7280126 5303718 8327606 9077712 1705788 9903866 4999968 9999936 4999968 555552 7222176 9999936 6543168 1543200 4999968 7222176 6543168 61728 1360000 6560000 3664000 6560000 6560000 4608000 10000000 2960000 6560000 1152000 2320000 3664000 1709400 5470...
output:
0 1 0 0 1 0 1 1 0 0 1 1 1 1 0 1 0 1 0 0
result:
ok 20 lines
Test #11:
score: 0
Accepted
time: 439ms
memory: 4644kb
input:
20 2615382 9846144 9999990 9846144 9999990 9999990 9999990 2769228 2615382 9999990 2769228 9999990 9191125 9999944 4779385 1323522 9191125 6544081 6544081 9999944 9191125 1323522 9191125 4779385 7028892 1743768 1991340 7028892 7028892 1743768 8234460 4865328 7028892 2378844 7599384 9999756 9731530 4...
output:
1 1 0 1 1 1 0 0 1 0 0 0 1 1 1 1 0 1 1 1
result:
ok 20 lines
Test #12:
score: 0
Accepted
time: 607ms
memory: 4732kb
input:
20 4999960 6173420 3316300 4999960 4999960 9999920 459180 459180 918360 1632640 459180 3316300 6328125 5078125 156250 5078125 6328125 10000000 6328125 5078125 10000000 6328125 156250 5078125 9979836 8089680 8280504 7601784 7634364 7141536 5377824 7028244 4492560 5815068 7928868 4377312 720000 800000...
output:
1 1 0 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 1
result:
ok 20 lines
Test #13:
score: 0
Accepted
time: 550ms
memory: 4512kb
input:
20 9999916 1689175 5743195 5743195 878371 4999958 9999916 4999958 4999958 1689175 878371 4999958 6301605 4049556 6301605 2024778 4049556 2024778 7293333 330576 6301605 9999924 6115656 3388404 617280 7901184 6543168 617280 123456 987648 4999968 4999968 9999936 1543200 6543168 4999968 3828125 1953125 ...
output:
1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 0 0 0 0 1
result:
ok 20 lines
Test #14:
score: 0
Accepted
time: 393ms
memory: 4452kb
input:
20 9999720 2888808 3555456 7610898 3555456 7610898 4944306 8805309 1805505 7610898 7610898 3555456 4999968 4999968 9999936 6543168 1543200 2530848 987648 9999936 6543168 1543200 987648 2530848 4999967 2358475 5471662 754712 5471662 9999934 754712 4999967 2358475 4999967 9999934 4999967 5371860 20661...
output:
0 1 1 0 0 1 1 1 0 1 0 0 1 0 1 1 1 1 1 0
result:
ok 20 lines
Test #15:
score: 0
Accepted
time: 608ms
memory: 4400kb
input:
20 4999968 4999968 9999936 4999968 5555520 555552 5555520 3402756 1180548 1180548 2222208 1736100 2207678 4505792 4722268 6840476 4330164 8510736 5829672 8496568 9904306 4191336 5368108 9200414 2644740 821072 2890020 3199420 6624380 4992680 6593608 7493780 2880304 9678732 5684644 8431388 9999920 433...
output:
1 0 0 1 0 0 0 1 1 0 1 1 1 1 0 1 0 1 1 0
result:
ok 20 lines
Test #16:
score: 0
Accepted
time: 503ms
memory: 4424kb
input:
20 8136144 6408528 8054156 7239584 6536596 1012996 1884652 5391096 6567204 1480764 5442988 5704872 9999936 4999968 4999968 902772 5069412 6944400 4999968 902772 5069412 3611088 4999968 277776 6358573 6634433 717236 2110329 2013778 1558609 9737858 9999925 6634433 717236 6634433 6634433 8820735 572387...
output:
0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 0 1 1 1 0
result:
ok 20 lines
Test #17:
score: 0
Accepted
time: 475ms
memory: 4440kb
input:
20 1479580 2551000 2499980 1479580 5408120 2499980 4999960 9999920 4999960 408160 5408120 4999960 1418208 6119592 6943616 4717024 1703128 4933672 8516320 2379048 9953024 6649448 9056784 2567000 6639370 1661665 8301033 6639370 8297389 8301033 1658021 6639370 1661665 8297389 6639370 1658021 8390964 71...
output:
1 0 1 0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 1
result:
ok 20 lines
Test #18:
score: 0
Accepted
time: 460ms
memory: 4688kb
input:
20 7346880 3775480 2551000 408160 3775480 3775480 4999960 3775480 204080 4999960 9999920 4999960 1493307 3497157 3289248 8523972 9198432 4312377 9709335 6351264 6294204 6821208 8165214 7286535 3024672 1543200 1111104 4999968 5246880 246912 4444416 5246880 1543200 4999968 4999968 9999936 3773520 1886...
output:
1 0 1 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 1
result:
ok 20 lines
Test #19:
score: -100
Wrong Answer
time: 1ms
memory: 3812kb
input:
20 2352936 2941170 9999978 6522477 1470585 8062266 9999978 4999989 4999989 1245672 4999989 1470585 816320 1326520 1734680 4999960 9999920 4999960 5306080 2653040 2653040 5306080 1020400 9999920 1592350 9745182 5222908 5222908 9999958 9745182 6369400 9745182 1592350 6369400 9745182 9999958 5103567 38...
output:
91.3698 822.328 913.698 451.773 25.3805 365.479 999.992 451.773 822.328 999.992 634.513 822.328 499.933 173.981 640.44 983.5 755.322 988.493 770.965 287.976 679.346 35.8788 246 274.849 999.993 801.881 84.9051 37.7356 764.146 801.881 764.146 915.088 150.942 999.993 915.088 764.146 35.7049 447....
result:
wrong answer 1st lines differ - expected: '0', found: ''