题目描述
Two points A (x1, y1, z1) and B (x2, y2, z2) are placed on the surface of parallelepiped with dimensions (see figure 1). These two points can be linked with various curves lying on the surface of P. You are to find out the square of the shortest curve length. Parallelepiped dimensions L, W, H and coordinates of the points are integers, .
输入
Input contains (in indicated order): L, W, H, x1, y1, z1, x2, y2, z2. The numbers are separated with spaces and end-of-line characters.
输出
Output should contain the square of the shortest curve length between points A and B on the surface of P.
样例输入
5 5 2
3 1 2
3 5 0
样例输出
36
解题思路
代码是cv的,之前走入一个误区,以为能分三个部分,把他们拉入一个框,在求距离,结果wa了一天,后面看到大神的代码仔细思考,先是把x1,y1,z1这个点转到最下边,也就是z1==0.将这个面设为0 0,由于每个面最多只需转两次,用个递归来求就可以了,其实每转一次,就将x1那个面相当于展开到旁边,所以能保证坐标轴不用变,只需x2那个点的z2转到0就可以直接求距离,不同展开面求出来的距离可能不同,所以很阴险这道题。。。
代码
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int maxint = 0x7FFFFFFF;
int ans;
void walk(int i, int j, int x0, int y0, int x, int y, int z, int l, int w,