제출 #1224937

#제출 시각아이디문제언어결과실행 시간메모리
1224937PenguinsAreCuteFences (JOI18_fences)C++17
0 / 100
0 ms324 KiB
#include <bits/stdc++.h> using namespace std; using ld = long double; pair<ld,ld> nearest(int a, int b, int c, int d, int x, int y) { pair<ld,ld> ln1 = {(d-b)/ld(c-a), 0}; ln1.second = b - ln1.first * a; pair<ld,ld> ln2 = {-1/ln1.first,0}; ln2.second = y - ln2.first * x; pair<ld,ld> isect = {0,0}; isect.first = (ln2.second - ln1.second) / (ln1.first - ln2.first); if(isect.first < a && isect.first < c) isect.first = min(a, c); if(isect.first > a && isect.first > c) isect.first = max(a, c); isect.second = ln1.first * isect.first + ln1.second; return isect; } ld dist(ld x, ld y) {return sqrt(x * x + y * y);} ld tot(int a, int b, int c, int d, int x1, int y1, int x2, int y2) { pair<ld,ld> p1 = nearest(a,b,c,d,x1,y1); pair<ld,ld> p2 = nearest(a,b,c,d,x2,y2); return dist(p1.first-p2.first,p1.second-p2.second)+dist(x1-p1.first,y1-p1.second)+dist(x2-p2.first,y2-p2.second); } int main() { int n, s, a, b, c, d; cin >> n >> s; cin >> a >> b >> c >> d; if(a == c || b == d) { cout << 8 * s; return 0; } ld ans = 0; ans = min(ans, tot(a,b,c,d,s,s,s,-s) - 2*s); ans = min(ans, tot(a,b,c,d,s,-s,-s,-s) - 2*s); ans = min(ans, tot(a,b,c,d,-s,-s,-s,s) - 2*s); ans = min(ans, tot(a,b,c,d,-s,s,s,s) - 2*s); ans = min(ans, tot(a,b,c,d,s,s,-s,-s) - 4*s); ans = min(ans, tot(a,b,c,d,s,-s,-s,s) - 4*s); cout << fixed << setprecision(10) << (ans + 8 * s); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...