QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#546145 | #8081. Minimum Manhattan Distance | potential | AC ✓ | 295ms | 4032kb | C++20 | 3.2kb | 2024-09-03 20:16:12 | 2024-09-03 20:16:13 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
# define int long long
# define lowbit(x) (x & (-x))
# define fi first
# define se second
// # define endl '\n'
inline int Read();
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int N = 1e6 + 10;
map <int, int> mp;
vector <int> v;
const double eps = 1e-8;
const double pi = acos(-1.0);
int sgn(double x){
if (fabs(x) < eps) return 0;
return x > 0 ? 1 : -1;
}
struct Point{
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point b) { return Point(x + b.x, y + b.y); }
Point operator-(Point b) { return Point(x - b.x, y - b.y); }
Point operator*(double k) { return Point(x * k, y * k); }
Point operator/(double k) { return Point(x / k, y / k); }
Point operator==(Point b) { return sgn(x - b.x) == 0 && sgn(y - b.y) == 0; }
};
double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
struct Line{
Point p1, p2;
Line(Point p1, Point p2) : p1(p1), p2(p2) {}
};
double len2(Point a) { return dot(a, a); }
double distance(Point a, Point b) { return hypot(a.x - b.x, a.y - b.y); }
double dis_point_line(Point p, Line v){
return fabs(cross(p - v.p1, v.p2 - v.p1)) / distance(v.p1, v.p2);
}
Point point_line_proj(Point p, Line v){
double k = dot(v.p2 - v.p1, p - v.p1) / len2(v.p2 - v.p1);
return v.p1 + (v.p2 - v.p1) * k;
}
// 1、圆的定义
struct Circle{
Point c;
double r;
Circle(Point c, double r = 0) : c(c), r(r) {}
Circle(double x = 0, double y = 0, double _r = 0){
c = Point(x, y);
r = _r;
}
};
// 2、点和圆心的距离
int point_circle_relation(Point p, Circle c){
double dis = distance(p, c.c);
if (sgn(dis - c.r) < 0) return 0; // 内
if (sgn(dis - c.r) == 0) return 1; // 上
return 2; // 外
}
// 3、直线和圆关系
int line_circle_relation(Line v, Circle c){
double dis = dis_point_line(c.c, v);
if (sgn(dis - c.r) < 0) return 0; // 交
if (sgn(dis - c.r) == 0) return 1; // 切
return 2; // 外
}
// 4、线段和圆关系
int seg_circle_relation(Line v, Circle c){
double dis = dis_point_line(c.c, v);
if (sgn(dis - c.r) < 0) return 0; // 内
if (sgn(dis - c.r) == 0) return 1; // 切
return 2; // 外
}
Point a[4];
void Solve(){
for(int i = 0; i < 4; i ++){
double x, y;
cin >> x >> y;
a[i] = {x, y};
}
Point cc1 = (a[1] + a[0]) / 2.0;
Point cc2 = (a[2] + a[3]) / 2.0;
double r1 = distance(a[0], a[1]) / 2;
double r2 = distance(a[2], a[3]) / 2;
printf("%.10f\n", (fabs(cc1.x - cc2.x) + fabs(cc1.y - cc2.y)- sqrt(2.0) * r2));
}
signed main(){
// IOS;
int T = 1;
cin >> T;
while (T--)
Solve();
return 0;
}
inline int Read(){
int x = 0, f = 1; char c = getchar();
while (c < '0' || c > '9'){ if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3864kb
input:
1 0 0 2 1 4 5 5 2
output:
4.2639320225
result:
ok Your answer is acceptable!^ ^
Test #2:
score: 0
Accepted
time: 288ms
memory: 3980kb
input:
100000 64184 -33682 59295 3067 16568 83379 -30901 17899 4747 16156 33365 80028 -41011 -93961 -89583 -95743 96914 -33206 12828 -88885 -93518 29681 -82022 42270 40225 76998 25677 84480 66361 -32945 94822 -81258 -17979 41800 -91442 80586 40229 -78184 30070 -89624 -21082 -94587 48262 -87979 -95197 91518...
output:
77664.4926864032 192928.3027014407 227607.1060353066 145831.4445800461 224138.5231894689 203168.4163226262 106258.7021872966 114459.0303484890 130191.3783434083 92639.9951336741 110927.1824394682 121482.2553263667 130471.0514280389 193239.8699309033 101942.1776022449 228879.0586081132 128129.5646587...
result:
ok Your answer is acceptable!^ ^
Test #3:
score: 0
Accepted
time: 292ms
memory: 3780kb
input:
100000 -18320 -12065 -63211 -70160 25465 23684 51590 90971 320 47201 7943 81396 -92700 -32637 -74486 -4692 99421 19908 91756 -28366 25529 -55621 18271 -78859 27654 -68417 31755 -96497 -26728 -28568 -50384 -393 -10805 -86093 7305 -27809 -64498 85696 -76254 19562 84518 11339 26149 17948 2447 55045 -13...
output:
126693.5251104599 147100.7153420607 119484.9246639657 110223.1867366585 130709.1080385253 92808.2702382451 118867.0018466377 297697.8711296911 213765.6021670809 90968.3578071120 165745.3674350864 184370.1691443061 184241.4668863199 132742.8313684500 129347.6125795355 119503.6265994220 155451.8100315...
result:
ok Your answer is acceptable!^ ^
Test #4:
score: 0
Accepted
time: 295ms
memory: 3932kb
input:
100000 37495 80384 -22610 56295 -62653 -47270 -62203 -6381 -86440 63964 25226 91598 62192 -71344 39815 -45590 -81947 13219 -50302 92935 70951 -12452 44060 -68999 68612 -63329 67331 -30225 21098 36822 -86721 85311 14179 56408 37664 -10185 -71446 -35104 -83185 -35928 62231 49184 -22420 -2128 -38074 -9...
output:
136120.8599278843 193733.8378780137 173156.7216895061 125031.8833013154 153543.3493283681 166748.4758589520 185481.0617343163 177488.0896438977 108138.4798974022 180039.8292054971 161614.8798608724 157287.7645108393 153821.0441204849 64625.5729642737 85310.0780332704 142744.0036289379 105454.5248094...
result:
ok Your answer is acceptable!^ ^
Test #5:
score: 0
Accepted
time: 267ms
memory: 3976kb
input:
100000 29660 -79759 63721 -76194 73610 -35151 84824 -12411 -87524 -63981 -79091 -72979 2216 18174 -8275 -10477 43042 -7367 6840 -22825 -37089 39403 -11737 74216 -38578 -60298 -11315 -54231 -74974 27413 -80834 23157 54452 -75442 29525 -46682 -90307 -93765 -98254 -98119 -89611 -83470 -51787 -86428 527...
output:
68793.5115528386 131031.7360151959 90807.3336320714 130385.8118566098 164741.4995122903 265321.8837562677 164666.5989041324 86404.2341932804 199326.1694970803 86550.2675616785 120915.3816180656 124345.8379354455 214598.2838239608 143475.1043659963 110486.5846793333 190341.2537372062 62166.1715781831...
result:
ok Your answer is acceptable!^ ^
Test #6:
score: 0
Accepted
time: 250ms
memory: 3936kb
input:
100000 -559 -590 -265 -338 671 670 -34 551 266 -278 -592 281 958 638 806 872 -34 809 -373 949 380 -847 962 -208 863 -691 927 578 -730 -913 -793 -956 -88 -133 -470 74 726 -585 769 -641 143 -383 -500 -361 836 580 434 512 -103 -967 554 -855 -226 383 -760 -57 920 749 626 979 202 392 -661 -403 -505 315 -...
output:
1299.4379365498 1601.1931324054 1669.8351286273 2480.5648537594 1560.0750563345 1443.2050121837 1303.2372893833 1042.3030673794 2227.7925552260 1408.9287187041 1608.7501069290 1105.6004872770 1662.5854584455 868.0753009575 1995.4705771543 1728.4533588583 1730.0476622805 1538.0356101900 915.583636741...
result:
ok Your answer is acceptable!^ ^
Test #7:
score: 0
Accepted
time: 230ms
memory: 4032kb
input:
100000 20 -100 98 -47 -10 21 -100 92 26 5 23 45 -48 -22 -13 -33 85 -56 88 -92 3 26 -100 -16 90 39 53 -1 17 -55 -67 -75 -88 31 -99 14 -58 -12 -64 -10 -76 -17 -46 -79 -13 92 77 56 95 -73 19 -34 -46 38 -5 4 20 -43 79 -4 -76 84 -41 89 -58 -38 -15 -55 -97 21 -76 23 -70 -78 -32 -46 70 91 50 -18 84 -91 100...
output:
162.9413792370 81.5577564579 135.3456930613 119.4426499101 61.5278640450 146.4580420472 119.3370208295 193.0000000000 103.5835661098 131.1386574898 186.9150721274 187.3082816414 160.3920493694 89.2799812734 99.1440092332 105.3857039287 192.0151549951 154.9955358922 75.8479182621 247.6360389693 238.5...
result:
ok Your answer is acceptable!^ ^
Test #8:
score: 0
Accepted
time: 217ms
memory: 3976kb
input:
100000 2 7 -6 8 -9 -5 -10 -7 2 4 2 8 -3 -10 -10 -2 4 0 -3 -2 8 -7 8 -10 -7 4 -3 -4 8 -7 8 -10 -10 4 2 4 8 -10 8 -7 4 1 5 6 -7 -4 -10 -4 8 1 6 5 -1 -8 -7 -3 -9 5 -6 8 2 -1 3 -2 -9 4 -10 7 6 -9 8 -1 -1 -4 3 -4 -10 -8 -7 -10 10 2 4 4 0 -7 -4 -4 -10 2 -7 8 4 -10 -1 -3 -9 -4 -6 -5 -1 2 8 4 1 8 -4 8 -7 -1...
output:
19.4188611699 12.9833518108 12.8786796564 19.3786796564 22.3786796564 18.3786796564 13.9773194914 17.0000000000 21.1690481052 11.9504902432 13.9644660941 15.4172374697 11.9807975948 22.2639320225 13.2573593129 21.9504902432 14.4807975948 11.0227507999 18.5845240526 4.4188611699 18.8786796564 18.4833...
result:
ok Your answer is acceptable!^ ^
Extra Test:
score: 0
Extra Test Passed