三维方块切割

垃圾版三维切割 待完善

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int > pr;
typedef queue<pr>  QP;
#define mk make_pair
#define random(x) (rand()%x+1)
typedef vector<int  > VI;

int sku_name=1e4;
struct Cube
{
    Cube ( string s,int xe = 0, int ye = 0, int ze = 0 )
    {
        str=s;
        x = xe;
        y = ye;
        z = ze;
    }
    string str;
    int x, y, z;
};
class Cut
{
public:
    void input (int ,int ,int ,int ,int );
    void run();
    vector<vector<Cube>  > box_plan;
    private:
    int nums;//方案数量规模,非准确;
    int length;//方块长;
    int width;// 宽
    int height;//高
    int plan_num;
    vector<Cube > plan;//计划分割的方案;

    void bfs ( int, int, int, int   ); //寻找一次方案
};


void Cut::input(int n ,int x,int y,int z,int p )
{
    nums=n;
    length=x;
    width=y;
    height=z;
    plan_num=p;

}
void Cut::run()
{

    for(int i=0;i<plan_num;i++)
    {
        bfs(length,width,height,nums);
    }

}
void Cut::bfs ( int xs, int ys, int zs, int nums )
{
    QP temp;
    temp.push ( mk ( xs, ys ) );
    int x, y, z;

    while ( temp.size() <= nums / 3 )
    {
        x = temp.front().first;
        y = temp.front().second;
        temp.pop();

        int cut_x, cut_y;

        while ( 1 )
        {
            cut_x = random ( x );
            cut_y = random ( y );

            if ( cut_x || cut_y ) break;
        }

        if ( cut_x && cut_y )
            temp.push ( mk ( cut_x, cut_y ) ) ;

        temp.push ( mk ( cut_x, y - cut_y ) );
        temp.push ( mk ( x - cut_x, y ) );

    }
    plan.clear();
    stringstream ss;
    string gg;
    while ( temp.size() )
    {
        x = temp.front().first;
        y = temp.front().second;
        temp.pop();
        z=zs;
        int times = 0, tz;
        while ( times < 5 && z )
        {

            tz = random ( z );
            if(times==4) tz=z;

            if(tz)
            {
                sku_name++;
                ss<<sku_name;
                ss>>gg;
                ss.clear();
                plan.push_back( Cube (gg, x, y, tz ) );
                z -= tz;
                times++;
            }

        }

    }
    box_plan.push_back(plan);
}


int main()
{

    Cut test;
    test.input(10,100,100,100,1);
    test.run();
    for(int i=0;i<test.box_plan.size();i++)
    {
        vector<Cube > q=test.box_plan[i];
        for(int j=0;j<q.size();j++)
        {
            cout<<q[j].str<<' '<<q[j].x<<' '<<q[j].y<<' '<<q[j].z<<endl;
        }
       // cout<<"xxxxxxxxxxxxxx           "<<endl;
    }
}











































  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值