Parallelepiped walk

题目链接
用递归把面展开

先把一个点移到最底面,之后开始展开操作。

整体向右展开,即除了当前底面之外,这个六面体往右边旋转,旋转后以底面左上角为(0,0)
整体向左展开,即除了当前底面之外,这个六面体往左边旋转,旋转后以底面左上角为(0,0)
整体向前展开,即除了当前底面之外,这个六面体往前边旋转,旋转后以底面左上角为(0,0)
整体向后展开,即除了当前底面之外,这个六面体往后边旋转,旋转后以底面左上角为(0,0)

如果你想暴力,那情况不能少。 惨痛教训

当另一个点转到底面时,就计算出它们之间的值。

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#include<bits/stdc++.h>
#include<iostream>
#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const int mod = 999911659;
const int N = 1e6+10;

int ans = INF;
int l,w,h,x1,x2,y1,y2,z1,z2;
void slove(int zy, int qh, int x0, int y0, int x, int y, int z, int l, int w, int h){
    if (z == 0)
        ans = min((x0 - x) * (x0 - x) + (y0 - y) * (y0 - y), ans);
    else{
        if (zy >= 0 && zy < 2)//向右转 (以转点为(0,0)点) 
            slove(zy + 1, qh, x0, y0 - w, x, z, w - y, l, h, w);
        if (zy <= 0 && zy > -2)//向左转 
            slove(zy - 1, qh, x0, y0 + h, x, h - z, y, l, h, w);
        if (qh >= 0 && qh < 2)//向前 
            slove(zy, qh + 1, x0 - l, y0, z, y, l - x, h, w, l);
        if (qh <= 0 && qh > -2)//向后 
            slove(zy, qh - 1, x0 + h, y0, h - z, y, x, h, w, l);
    }
}

signed main(){
	IOS;
	#ifdef ddgo
		freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin);
	#endif
	
	while(cin>>l>>w>>h>>x1>>y1>>z1>>x2>>y2>>z2){
		//预处理让第一个点在下方 
		if (z1 != 0 && z1 != h){
            if (y1 != 0 && y1 != w) swap(x1, z1),swap(x2, z2),swap(l, h);
            else swap(y1, z1),swap(y2, z2),swap(w, h); 
        }
        if (z1 == h) z1 = 0, z2 = h - z2;
        ans = 1e18;
        slove(0, 0, x1, y1, x2, y2, z2, l, w, h);
		cout<<ans<<endl;
	}
	return 0;
}

总结:我是傻逼

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是程序实现: ```cpp #include <iostream> #include <cmath> using namespace std; class Shape { public: virtual void showData() = 0; virtual double reArea() = 0; virtual double reVolume() = 0; }; class TwoDimShape : public Shape { protected: double x, y; public: TwoDimShape(double a, double b) : x(a), y(b) {} virtual void showData() = 0; virtual double reArea() = 0; }; class ThreeShape : public Shape { protected: double x, y, z; public: ThreeShape(double a, double b, double c) : x(a), y(b), z(c) {} virtual void showData() = 0; virtual double reArea() = 0; virtual double reVolume() = 0; }; class Circle : public TwoDimShape { public: Circle(double r) : TwoDimShape(r, 0) {} void showData() { cout << "Circle, radius: " << x << endl; } double reArea() { return M_PI * x * x; } }; class Elipse : public TwoDimShape { public: Elipse(double a, double b) : TwoDimShape(a, b) {} void showData() { cout << "Elipse, axis a: " << x << ", axis b: " << y << endl; } double reArea() { return M_PI * x * y; } }; class Rectangle : public TwoDimShape { public: Rectangle(double a, double b) : TwoDimShape(a, b) {} void showData() { cout << "Rectangle, width: " << x << ", height: " << y << endl; } double reArea() { return x * y; } }; class Triangle : public TwoDimShape { public: Triangle(double a, double b) : TwoDimShape(a, b) {} void showData() { cout << "Triangle, base: " << x << ", height: " << y << endl; } double reArea() { return x * y / 2; } }; class Ball : public ThreeShape { public: Ball(double r) : ThreeShape(r, 0, 0) {} void showData() { cout << "Ball, radius: " << x << endl; } double reArea() { return 4 * M_PI * x * x; } double reVolume() { return 4.0 / 3.0 * M_PI * x * x * x; } }; class Cylinder : public ThreeShape { public: Cylinder(double r, double h) : ThreeShape(r, h, 0) {} void showData() { cout << "Cylinder, radius: " << x << ", height: " << y << endl; } double reArea() { return 2 * M_PI * x * x + 2 * M_PI * x * y; } double reVolume() { return M_PI * x * x * y; } }; class RectangularParallelepiped : public ThreeShape { public: RectangularParallelepiped(double a, double b, double c) : ThreeShape(a, b, c) {} void showData() { cout << "Rectangular parallelepiped, length: " << x << ", width: " << y << ", height: " << z << endl; } double reArea() { return 2 * (x * y + x * z + y * z); } double reVolume() { return x * y * z; } }; int main() { Shape* shapes[8]; shapes[0] = new Circle(2.5); shapes[1] = new Elipse(3.0, 4.5); shapes[2] = new Rectangle(5.0, 4.0); shapes[3] = new Triangle(6.0, 3.0); shapes[4] = new Ball(2.0); shapes[5] = new Cylinder(3.0, 5.0); shapes[6] = new RectangularParallelepiped(4.0, 3.0, 2.0); shapes[7] = new RectangularParallelepiped(1.0, 2.0, 3.0); for (int i = 0; i < 8; i++) { shapes[i]->showData(); cout << "Area: " << shapes[i]->reArea() << endl; cout << "Volume: " << shapes[i]->reVolume() << endl; cout << endl; } for (int i = 0; i < 8; i++) { delete shapes[i]; } return 0; } ``` 输出结果: ``` Circle, radius: 2.5 Area: 19.6349 Volume: 0 Elipse, axis a: 3, axis b: 4.5 Area: 42.4115 Volume: 0 Rectangle, width: 5, height: 4 Area: 20 Volume: 0 Triangle, base: 6, height: 3 Area: 9 Volume: 0 Ball, radius: 2 Area: 50.2655 Volume: 33.5103 Cylinder, radius: 3, height: 5 Area: 150.796 Volume: 141.372 Rectangular parallelepiped, length: 4, width: 3, height: 2 Area: 52 Volume: 24 Rectangular parallelepiped, length: 1, width: 2, height: 3 Area: 22 Volume: 6 ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值