Packing Rectangles(USACO)

/* ID:tianlin2 PROG:packrec LANG:C++ */ #include #include #define INF 32768 using namespace std; class rect { public: int x; int y; int area; rect() { x=0; y=0; area=0; } rect operator=(rect a) { x=a.x; y=a.y; area=a.area; return *this; } }; void bubble(rect a[],int n) { int b=0; while(!b){ b=1; for(int i=0;i!=n-1;++i){ if(a[i].x>a[i+1].x){ rect temp=a[i]; a[i]=a[i+1]; a[i+1]=temp; b=0; } } } } int max(int a,int b,int c) { if(a>=b&&a>=c) return a; else if(b>=a&&b>=c) return b; else if(c>=a&&c>=b) return c; } int max(int a,int b) { if(a>b) return a; return b; } int states[24]={1234,1243,1324,1342,1423,1432,2134,2143,2314,2341,2413,2431,3124,3142,3214,3241,3412,3421,4123,4132,4213,4231,4312,4321}; int states3[6]={123,132,213,231,312,321}; rect re[4]; //长x,短y void chan(int& w,int& h,int s) { w=re[s].x; h=re[s].y; } void swap(int &a,int &b) { int temp=a; a=b; b=temp; } int main() { ifstream fin("packrec.in"); ofstream fout("packrec.out"); int mycount=0; int minar=INF; int count=0; for(int i=0;i!=4;++i){ fin>>re[i].x>>re[i].y; if(re[i].x=h2+h4) minw5=max(w1,w3+w2,w3+w4); else if(h3>h4&&h3h3&&h4=h1+h3) minw5=max(w2,w4+w1,w4+w3); else if(h4==h3) minw5=max(w1+w2,w3+w4); if(minw5

你可能感兴趣的:(算法练习)