USACO Section 1.4 Packing Rectangles
来源:互联网 发布:金鲁班预算软件下载 编辑:程序博客网 时间:2024/05/30 04:08
题意:
已知4个矩形的l和w 矩形可以旋转和平移 用一块最小面积的新的矩形覆盖4个矩形
求最小的面积 以及新矩形的l和w
思路:
题目已经给出6种摆放方式 按它的方式摆即可
我们要枚举4个矩形是否旋转(只转90度)过 然后枚举每种摆放方式中矩形的编号
代码中的枚举方法是二进制枚举旋转 全排列枚举编号
最后计算所有情况中的答案
第6种摆放方式比较难想 大致思路就是 先放下面两块 在根据下面两块的高度分别讨论上面两块如何摆放
/*ID: housera1PROG: packrecLANG: C++*/#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct rectangle{int l,w;}f[5];pair<int,int> sol[5005];int n,ans=2147483640;int order[5];int main(){int Debug=0;if(!Debug){freopen("packrec.in","r",stdin);freopen("packrec.out","w",stdout);}int i,j,x,y;for(i=0;i<4;i++) scanf("%d%d",&f[i].l,&f[i].w);for(i=0,n=0;i<16;i++){for(j=0;j<4;j++) if(i&(1<<j)) swap(f[j].l,f[j].w);for(j=0;j<4;j++) order[j]=j;do{x=f[order[0]].w+f[order[1]].w+f[order[2]].w+f[order[3]].w;y=max(f[order[0]].l,max(f[order[1]].l,max(f[order[2]].l,f[order[3]].l)));if(x*y<=ans){if(x*y<ans) n=0,ans=x*y;if(x>y) swap(x,y);sol[n++]=make_pair(x,y);}x=max(f[order[0]].w,f[order[1]].w+f[order[2]].w+f[order[3]].w);y=f[order[0]].l+max(f[order[1]].l,max(f[order[2]].l,f[order[3]].l));if(x*y<=ans){if(x*y<ans) n=0,ans=x*y;if(x>y) swap(x,y);sol[n++]=make_pair(x,y);}x=max(f[order[0]].w,f[order[1]].w+f[order[2]].w)+f[order[3]].w;y=max(f[order[0]].l+max(f[order[1]].l,f[order[2]].l),f[order[3]].l);if(x*y<=ans){if(x*y<ans) n=0,ans=x*y;if(x>y) swap(x,y);sol[n++]=make_pair(x,y);}x=f[order[0]].w+max(f[order[1]].w,f[order[2]].w)+f[order[3]].w;y=max(f[order[0]].l,max(f[order[1]].l+f[order[2]].l,f[order[3]].l));if(x*y<=ans){if(x*y<ans) n=0,ans=x*y;if(x>y) swap(x,y);sol[n++]=make_pair(x,y);}x=max(f[order[0]].w,f[order[1]].w)+f[order[2]].w+f[order[3]].w;y=max(f[order[0]].l+f[order[1]].l,max(f[order[2]].l,f[order[3]].l));if(x*y<=ans){if(x*y<ans) n=0,ans=x*y;if(x>y) swap(x,y);sol[n++]=make_pair(x,y);}if(f[order[1]].l==f[order[2]].l) x=max(f[order[1]].w+f[order[2]].w,f[order[0]].w+f[order[3]].w);else if(f[order[1]].l<f[order[2]].l) x=max(f[order[1]].w+f[order[2]].w,f[order[0]].w+max(f[order[2]].w,f[order[3]].w));else if(f[order[1]].l>f[order[2]].l) x=max(f[order[1]].w+f[order[2]].w,f[order[3]].w+max(f[order[0]].w,f[order[1]].w));y=max(f[order[0]].l+f[order[1]].l,f[order[2]].l+f[order[3]].l);if(x*y<=ans){if(x*y<ans) n=0,ans=x*y;if(x>y) swap(x,y);sol[n++]=make_pair(x,y);}}while(next_permutation(order,order+4));for(j=0;j<4;j++) if(i&(1<<j)) swap(f[j].l,f[j].w);}printf("%d\n",ans);sort(sol,sol+n);for(i=0;i<n;i++){if(i!=0&&sol[i].first==sol[i-1].first&&sol[i].second==sol[i-1].second) continue;printf("%d %d\n",sol[i].first,sol[i].second);}return 0;}
0 0
- USACO Section 1.4 Packing Rectangles
- USACO Section 1.4 Packing Rectangles
- [USACO Section 1.4] Packing Rectangles (模拟)
- Section 1.4 Packing Rectangles
- USACO 1.4-Packing Rectangles
- USACO 1.4 Packing Rectangles
- USACO Section 1.4 Packing Rectangles (POJ 1169)搜索
- USCAO section 1.4 Packing Rectangles
- USACO 1.4.1 packing rectangles
- USACO 1.4.1Packing Rectangles
- [USACO 1.4.1] Packing Rectangles
- usaco 1.4.2 Packing Rectangles
- usaco 1.4.1 Packing Rectangles
- [搜索]USACO-1.4-Packing Rectangles
- USACO 1.4.1 Packing Rectangles
- USACO 1.4.1 Packing Rectangles
- USACO 1.4 Packing Rectangles (packrec)
- USACO--Packing Rectangles
- 什么是内存泄漏
- libjson使用详解(linux和windows)
- What are the numbers that every computer engineer should know, according to Jeff Dean?
- extjs
- Query 操作手册 (新增逻辑数据库)
- USACO Section 1.4 Packing Rectangles
- STM8 TIM2 定时器的问题
- sgu 148 B-Station 枚举+小根堆
- 华硕wl 700ge 路由器 刷OpenWrt 过程记录
- HDU 1370(中国剩余定理)
- 给虚拟机添加磁盘容量
- unity3d 虚拟现实在各行业的应用
- 内存池设计
- POJ 3292 Semi-prime H-numbers (数论)