比赛 |
2022级DP专题练习赛8 |
评测结果 |
AWWWWEEEEEEEEEE |
题目名称 |
Springboards |
最终得分 |
6 |
用户昵称 |
HeSn |
运行时间 |
1.883 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2023-03-01 19:43:34 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int m, n, xa[1010], xb[1010], ya[1010], yb[1010], dis[1010], vis[1010];
vector<int> cd[1010], w[1010];
queue<int> q;
int dist(int x, int y, int a, int b) {
return x + y - a + b;
}
signed main() {
freopen("usaco_Jan_boards.in", "r", stdin);
freopen("usaco_Jan_boards.out", "w", stdout);
cin >> m >> n;
for(int i = 1; i <= n; i ++) {
cin >> xa[i] >> ya[i] >> xb[i] >> yb[i];
}
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= n; j ++) {
if(i == j) {
continue;
}
if(xa[j] >= xb[i] && ya[j] >= yb[i]) {
cd[i].push_back(j);
w[i].push_back(dist(xa[j], ya[j], xb[i], yb[i]));
}
}
}
for(int i = 1; i <= n; i ++) {
cd[0].push_back(i);
w[0].push_back(dist(xa[i], ya[i], 0, 0));
if(xb[i] <= m && yb[i] <= m) {
cd[i].push_back(n + 1);
w[i].push_back(dist(m, m, xb[i], yb[i]));
}
}
memset(dis, 0x3f, sizeof(dis));
dis[0] = 0;
q.push(0);
while(!q.empty()) {
int x = q.front();
q.pop();
vis[x] = 0;
for(int i = 0; i < cd[x].size(); i ++) {
int u = cd[x][i];
if(dis[x] + w[x][i] < dis[u]) {
dis[u] = dis[x] + w[x][i];
if(!vis[u]) {
vis[u] = 1;
q.push(u);
}
}
}
}
cout << dis[n];
return 0;
}