垃圾版三维切割 待完善
#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;
}
}