比赛 |
20161223 |
评测结果 |
AAAAAAAAAA |
题目名称 |
萌化大革命 |
最终得分 |
100 |
用户昵称 |
KZNS |
运行时间 |
0.099 s |
代码语言 |
C++ |
内存使用 |
7.18 MiB |
提交时间 |
2016-12-23 19:52:17 |
显示代码纯文本
//KZNS
#include <cstdio>
#include <algorithm>
using namespace std;
#define Nmax 1003
inline int diss(int a, int b, int c, int d) {
return (a-c)*(a-c) + (b-d)*(b-d);
}
int A[Nmax][2];
int B[Nmax][2];
int H, G;
void init() {
scanf("%d %d", &H, &G);
for (int i = 1; i <= H; i++)
scanf("%d %d", &A[i][0], &A[i][1]);
for (int i = 1; i <= G; i++)
scanf("%d %d", &B[i][0], &B[i][1]);
}
int F[1003][1003][2];
void work() {
for (int i = 0; i <= H; i++)
for (int j = 0; j <= G; j++)
F[i][j][0] = F[i][j][1] = 0x7fffffff;
F[1][0][0] = 0;
for (int i = 1; i <= H; i++) {
for (int j = 0; j <= G; j++) {
if (F[i][j][0] < 0x7fffffff) {
if (i < H)
F[i+1][j][0] = min(F[i+1][j][0], F[i][j][0] + diss(A[i][0], A[i][1], A[i+1][0], A[i+1][1]));
if (j < G)
F[i][j+1][1] = min(F[i][j+1][1], F[i][j][0] + diss(A[i][0], A[i][1], B[j+1][0], B[j+1][1]));
}
if (F[i][j][1] < 0x7fffffff) {
if (i < H)
F[i+1][j][0] = min(F[i+1][j][0], F[i][j][1] + diss(B[j][0], B[j][1], A[i+1][0], A[i+1][1]));
if (j < G)
F[i][j+1][1] = min(F[i][j+1][1], F[i][j][1] + diss(B[j][0], B[j][1], B[j+1][0], B[j+1][1]));
}
}
}
printf("%d\n", F[H][G][0]);
}
int main() {
freopen("checklist.in", "r", stdin);
freopen("checklist.out", "w", stdout);
init();
work();
return 0;
}
//UBWH