QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#111334 | #6302. Map | ethening | WA | 2ms | 3764kb | C++17 | 2.2kb | 2023-06-06 19:48:19 | 2023-06-06 19:48:21 |
Judging History
answer
#include "bits/stdc++.h"
#include <array>
#include <cassert>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const double eps = 1e-8;
template<class T>
struct Point {
typedef Point P;
T x, y;
explicit Point(T x=0, T y=0) : x(x), y(y) {}
P operator+(P p) const { return P(x+p.x, y+p.y); }
P operator-(P p) const { return P(x-p.x, y-p.y); }
P operator*(T d) const { return P(x*d, y*d); }
P operator/(T d) const { return P(x/d, y/d); }
bool operator==(P p) const { return fabs(x-p.x)<=eps&&fabs(y-p.y)<=eps; }
bool operator!=(P p) const { return fabs(x-p.x)>eps||fabs(y-p.y)>eps; }
T dist2() const { return x*x + y*y; }
double dist() const { return sqrt((double)dist2()); }
friend ostream& operator<<(ostream& os, P p) {
return os << "(" << p.x << "," << p.y << ")"; }
};
void solve() {
Point<double> a1, b1, c1, d1;
Point<double> a2, b2, c2, d2;
cin >> a1.x >> a1.y >> b1.x >> b1.y >> c1.x >> c1.y >> d1.x >> d1.y;
cin >> a2.x >> a2.y >> b2.x >> b2.y >> c2.x >> c2.y >> d2.x >> d2.y;
Point<double> db1, dd1, db2, dd2;
db1 = b1 - a1, dd1 = d1 - a1;
// assert(a1 + db1 + dd1 == c1);
db2 = b2 - a2, dd2 = d2 - a2;
// assert(a2 + db2 + dd2 == c2);
auto f = [&](const Point<double> &pt) {
Point<double> diff = pt - a1;
double k1 = (diff.x * dd1.y - diff.y * dd1.x) / (db1.x * dd1.y - db1.y * dd1.x);
double k2 = (diff.x - k1 * db1.x) / dd1.x;
// assert(0 <= k1 + eps && k1 - eps <= 1);
// assert(0 <= k2 + eps && k2 - eps <= 1);
return a2 + db2 * k1 + dd2 * k2;
};
Point<double> S, T;
cin >> S.x >> S.y >> T.x >> T.y;
double k;
int n;
cin >> k >> n;
vector<Point<double>> ST(n + 1), TT(n + 1);
ST[0] = S, TT[0] = T;
for (int i = 1; i <= n; i++) {
ST[i] = f(ST[i - 1]);
TT[i] = f(TT[i - 1]);
// cout << ST[i] << " " << TT[i] << "\n";
}
double ans = 1e18;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (i + j > n) break;
double cur = k * (i + j);
cur += (ST[i] - TT[j]).dist();
ans = min(ans, cur);
}
}
cout << fixed << setprecision(9) << ans << "\n";
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3700kb
input:
2 0 0 0 2 4 2 4 0 0 0 0 1 2 1 2 0 2 1 4 2 1 1 0 0 0 3 6 3 6 0 0 1 1 0 3 2 2 3 0 0 4 2 0 3
output:
1.000000000 1.227262335
result:
ok 2 numbers
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3764kb
input:
100 -133 -128 -109 -134 -85 -38 -109 -32 -95 -37 -100 -35 -108 -55 -103 -57 -119 -130 -112 -44 2 73 5 -100 5 -8 1 -8 1 -100 1 -60 1 -14 3 -14 3 -60 3 -84 1 -20 2 53 -58 -78 -66 -78 -66 -34 -58 -34 -58 -34 -66 -34 -66 -78 -58 -78 -63 -50 -63 -37 4 54 52 -148 116 -148 116 -52 52 -52 53 -103 53 -71 101...
output:
9.500657500 12.229731079 -nan -nan 13.341664064 7.615773106 23.409399821 7.280109889 21.280037734 59.776022093 4.123105626 -nan 65.069193940 14.142135624 41.824615503 -nan 15.672617530 21.562202374 66.272166103 21.023796042 20.880613018 -nan 4.123105626 -nan -nan 14.715798597 -nan 40.816016544 53.59...
result:
wrong output format Expected double, but "-nan" found