usaco Packing Rectangles
生活随笔
收集整理的這篇文章主要介紹了
usaco Packing Rectangles
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
太惡心了
//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include<cmath> #include<climits> #include<string> #include<map> #include<queue> #include<vector> #include<stack> #include<set> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; #define pb(a) push(a) #define INF 0x1f1f1f1f #define lson idx<<1,l,mid #define rson idx<<1|1,mid+1,r #define PI 3.1415926535898 template<class T> T min(const T& a,const T& b,const T& c) {return min(min(a,b),min(a,c)); } template<class T> T max(const T& a,const T& b,const T& c) {return max(max(a,b),max(a,c)); } void debug() { #ifdef ONLINE_JUDGE #elsefreopen("d:\\in1.txt","r",stdin);freopen("d:\\out1.txt","w",stdout); #endif } int getch() {int ch;while((ch=getchar())!=EOF) {if(ch!=' '&&ch!='\n')return ch;}return EOF; } struct situation {int h[4],w[4]; }sit[500]; struct answer {int h,w;answer(int h=0,int w=0):h(h),w(w){}bool operator < (const answer &ant) const{if(h*w!=ant.h*ant.w)return h*w<ant.h*ant.w;else return h<ant.h;}bool operator == (const answer &ant ) const{return h==ant.h&&w==ant.w;} }ans[2500]; int h[4],w[4]; void get() {int k=0;for(int st=0;st<(1<<4);st++){int ord[4]={0,1,2,3};do{k++;for(int i=0;i<4;i++){if((1<<ord[i])&st){sit[k].h[i]=w[ord[i]];sit[k].w[i]=h[ord[i]];}else{sit[k].h[i]=h[ord[i]];sit[k].w[i]=w[ord[i]];}}}while(next_permutation(ord,ord+4));} }int deal() {int h,w;int k=0;for(int i=1;i<=24*16;i++){//1w=0,h=0;for(int j=0;j<4;j++){h=max(h,sit[i].h[j]);w+=sit[i].w[j];}if(h>w)swap(h,w);ans[++k]=answer(h,w);//2w=0,h=0;for(int j=0;j<3;j++){h=max(h,sit[i].h[j]);w+=sit[i].w[j];}h+=sit[i].h[3];w=max(w,sit[i].w[3]);if(h>w)swap(h,w);ans[++k]=answer(h,w);//3h=max(sit[i].h[0],sit[i].h[1])+sit[i].h[2]+sit[i].h[3];w=max(sit[i].w[0]+sit[i].w[1],sit[i].w[2],sit[i].w[3]);if(h>w)swap(h,w);ans[++k]=answer(h,w);//4h=max(sit[i].h[0],sit[i].h[1])+max(sit[i].h[2],sit[i].h[3]);w=max(sit[i].w[0]+sit[i].w[1],sit[i].w[2]+sit[i].w[3]);if(sit[i].w[0]+sit[i].w[1]>=sit[i].w[2]+sit[i].w[3]){if(sit[i].w[3]<=sit[i].w[0]&&sit[i].h[0]<=sit[i].h[1])h=max(sit[i].h[0]+sit[i].h[3],sit[i].h[1]+sit[i].h[2]);}if(h>w)swap(h,w);ans[++k]=answer(h,w);//5h=sit[i].h[0];h+=max(sit[i].h[1],sit[i].h[2]+sit[i].h[3]);w=max(sit[i].w[0],sit[i].w[1]+max(sit[i].w[2],sit[i].w[3]));if(h>w)swap(h,w);ans[++k]=answer(h,w);}return k; } int main() {freopen("packrec.in","r",stdin);freopen("packrec.out","w",stdout);for(int i=0;i<4;i++)scanf("%d %d",&h[i],&w[i]);get();int k=deal();sort(ans+1,ans+k+1);k=unique(ans+1,ans+k+1)-ans;int res=ans[1].h*ans[1].w;printf("%d\n%d %d\n",res,ans[1].h,ans[1].w);int i=2;while(ans[i].h*ans[i].w==res){printf("%d %d\n",ans[i].h,ans[i].w);i++;}return 0; } View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/BMan/p/3554488.html
總結(jié)
以上是生活随笔為你收集整理的usaco Packing Rectangles的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SharePoint 2013 APP
- 下一篇: 计算机启动过程