QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#170748 | #7184. Transport Pluses | ucup-team1303# | ML | 3ms | 4688kb | C++14 | 2.9kb | 2023-09-09 15:53:11 | 2023-09-09 15:55:41 |
Judging History
answer
#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> inline void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
const int N = 110;
int n, m, x[N], y[N], fr[N * N];//, kx[N], ky[N];
bool vis[N];
inline int id(int x, int y) {
return x * 101 + y;
}
pair <int, int> iid(int x) {
return make_pair((x - 1) / 101, (x - 1) % 101 + 1);
}
vector <pair <int, double>> v[N * N];
double f[N * N];
inline double calc(int kx, int ky, int tx, int ty) {
return sqrt((kx - tx) * (kx - tx) + (ky - ty) * (ky - ty));
}
signed main() {
cin >> n >> m;
int sx, sy, px, py;
cin >> sx >> sy >> px >> py;
int s = id(sx, sy), p = id(px, py);
int tot = id(100, 100), h = tot;
F(i, 1, n) {
read(x[i]), read(y[i]);
tot++;
F(j, 0, 100) {
// cout << x[i] << " " << j << " " << j << " " << y[i] << endl;
v[id(x[i], j)].emplace_back(tot, m);
v[id(j, y[i])].emplace_back(tot, m);
v[tot].emplace_back(id(x[i], j), 0);
v[tot].emplace_back(id(j, y[i]), 0);
}
}
priority_queue <pair <double, int>, vector <pair <double, int>>, greater <pair <double, int>>> q;
F(i, 0, 100)
F(j, 0, 100) {
// f[id(i, j)] = 1e18;
v[id(sx, sy)].emplace_back(id(i, j), calc(sx, sy, i, j));
// if (i == 1 && j == 2) cout << "~ " << calc(sx, sy, i, j) << endl;
v[id(i, j)].emplace_back(id(px, py), calc(px, py, i, j));
// if (i == 5 && j == 2) cout << fixed << setprecision(10) << calc(px, py, i, j) << endl;
// f[i] = calc(x[i], y[i], sx, sy);
}
F(i, 0, tot) f[i] = 1e18;
f[id(sx, sy)] = 0;
q.push(make_pair(0, id(sx, sy)));
while (q.size()) {
int x = q.top().second; q.pop();
// cout << x << " " << f[x] << endl;
for (auto [i, j]: v[x])
if (f[x] + j < f[i]) {
// if (x == s && i == p) {
// cout << "~~~ " << j << endl;
// }
f[i] = f[x] + j;
fr[i] = x;
q.push(make_pair(f[i], i));
}
}
// cout << f[id(5, 2)] << endl;
// cout << tot << " " << f[tot] << endl;
// cout << fr[p] << endl;
cout << fixed << setprecision(5) << f[p] << endl;
vector <pair <int, pair <int, int>>> ans;
while (p != s) {
if (fr[p] >= h) {
ans.emplace_back(fr[p] - h, iid(p));
p = fr[fr[p]];
} else {
ans.emplace_back(0, iid(p));
p = fr[p];
}
}
cout << ans.size() << endl;
DF(i, SZ(ans), 0) cout << ans[i].first << " " << ans[i].second.first << " " << ans[i].second.second << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4688kb
input:
1 2 1 1 5 3 6 2
output:
4.00000 3 0 1 2 1 5 2 0 5 3
result:
ok correct
Test #2:
score: 0
Accepted
time: 1ms
memory: 4548kb
input:
2 1 1 1 6 1 1 3 6 3
output:
2.00000 2 1 0 3 2 6 1
result:
ok correct
Test #3:
score: 0
Accepted
time: 3ms
memory: 4436kb
input:
0 0 1 1 1 1
output:
0.00000 0
result:
ok correct
Test #4:
score: -100
Memory Limit Exceeded
input:
0 0 100 100 0 0
output:
141.42136