'commit'
This commit is contained in:
38
TangDou/LanQiaoBei/LanQiaoBeiWhitePaper/17_XiaoQuLouFang.cpp
Normal file
38
TangDou/LanQiaoBei/LanQiaoBeiWhitePaper/17_XiaoQuLouFang.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
int a[N][N];
|
||||
int x = 20, w;
|
||||
int m, n;
|
||||
|
||||
int main() {
|
||||
cin >> w >> m >> n;
|
||||
//构建蛇形矩阵
|
||||
for (int i = 0; i < x * w; i++) {
|
||||
int r, c;
|
||||
r = i / w;
|
||||
c = i % w;
|
||||
if (r % 2) a[r][c] = (r + 1) * w - c;
|
||||
else a[r][c] = i + 1;
|
||||
}
|
||||
/*
|
||||
//输出构建结果
|
||||
for (int i = 0; i < x; i++) {
|
||||
for (int j = 0; j < w; j++)
|
||||
printf("%3d ", a[i][j]);
|
||||
printf("\n");
|
||||
}*/
|
||||
|
||||
//找出m和n的行列值
|
||||
int r1, c1, r2, c2;
|
||||
for (int i = 0; i < x; i++) {
|
||||
for (int j = 0; j < w; j++) {
|
||||
if (a[i][j] == m) r1 = i, c1 = j;
|
||||
if (a[i][j] == n) r2 = i, c2 = j;
|
||||
}
|
||||
}
|
||||
//计算距离
|
||||
printf("%d", abs(r2 - r1 + c2 - c1));
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user