SWUST OJ 530: Parallelepiped walk

SWUST OJ 530: Parallelepiped walk

题目描述

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, 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值