USACO Packing Rectangles
来源:互联网 发布:java字符串转日期代码 编辑:程序博客网 时间:2024/05/26 02:51
IOI 95
The six basic layouts of four rectangles
Four rectangles are given. Find the smallest enclosing (new) rectangle into which these four may be fitted without overlapping. By smallest rectangle, we mean the one with the smallest area.
All four rectangles should have their sides parallel to the corresponding sides of the enclosing rectangle. Figure 1 shows six ways to fit four rectangles together. These six are the only possible basic layouts, since any other layout can be obtained from a basic layout by rotation or reflection. Rectangles may be rotated 90 degrees during packing.
There may exist several different enclosing rectangles fulfilling the requirements, all with the same area. You must produce all such enclosing rectangles.
PROGRAM NAME: packrec
INPUT FORMAT
Four lines, each containing two positive space-separated integers that represent the lengths of a rectangle's two sides. Each side of a rectangle is at least 1 and at most 50.
SAMPLE INPUT (file packrec.in)
1 22 33 44 5
OUTPUT FORMAT
The output file contains one line more than the number of solutions. The first line contains a single integer: the minimum area of the enclosing rectangles. Each of the following lines contains one solution described by two numbers p and q with p<=q. These lines must be sorted in ascending order of p, and must all be different.SAMPLE OUTPUT (file packrec.out)
404 105 8
/*ID: qhn9992PROG: packrecLANG: C++*/#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int INF=0x3f3f3f3f;typedef pair<int,int> pII;int rect[5][2];int ANS[500][2],tot,MIN=INF;int a1,a2,a3,a4,b1,b2,b3,b4;void update(int weight,int height){ int area=weight*height; int mi=min(weight,height); int mx=max(weight,height); if(area>MIN) return ; else if(area<MIN) { tot=1; MIN=area; ANS[0][0]=mi;ANS[0][1]=mx; return ; } else { for(int i=0;i<tot;i++) { if(ANS[i][0]==mi&&ANS[i][1]==mx) return ; } ANS[tot][0]=mi;ANS[tot][1]=mx; tot++; }}void solve(){ int wide,high; int w1=rect[a1][b1],w2=rect[a2][b2],w3=rect[a3][b3],w4=rect[a4][b4]; int h1=rect[a1][1-b1],h2=rect[a2][1-b2],h3=rect[a3][1-b3],h4=rect[a4][1-b4]; ///cas1 wide=w1+w2+w3+w4; high=max(max(h1,h2),max(h3,h4)); update(wide,high); ///cas2 wide=max(w4,w1+w2+w3); high=max(h1,max(h2,h3))+h4; update(wide,high); ///cas3 wide=w4+max(w1+w2,w3); high=max(h4,max(h1,h2)+h3); update(wide,high); ///cas4/5 wide=w1+w4+max(w2,w3); high=max(h1,max(h2+h3,h4)); update(wide,high); ///cas6 if(h2>=h4&&(w2<w1||w3<w4)) wide=max(w2+w4,w1+w3); else wide=max(w1,w2)+max(w3,w4); high=max(h1+h2,h3+h4); update(wide,high);}int main(){ freopen("packrec.in","r",stdin); freopen("packrec.out","w",stdout); for(int i=0;i<4;i++) { int a,b; scanf("%d%d",&a,&b); rect[i][0]=a;rect[i][1]=b; } for(a1=0;a1<4;a1++) { for(a2=0;a2<4;a2++) { if(a1==a2) continue; for(a3=0;a3<4;a3++) { if(a3==a2||a3==a1) continue; a4=6-a1-a2-a3; for(b1=0;b1<2;b1++) for(b2=0;b2<2;b2++) for(b3=0;b3<2;b3++) for(b4=0;b4<2;b4++) solve(); } } } vector<pII> ans; for(int i=0;i<tot;i++) { int a=ANS[i][0],b=ANS[i][1]; ans.push_back(make_pair(a,b)); } sort(ans.begin(),ans.end()); printf("%d\n",MIN); for(int i=0;i<tot;i++) { printf("%d %d\n",ans[i].first,ans[i].second); } return 0;}
- USACO--Packing Rectangles
- USACO 1.4-Packing Rectangles
- Packing Rectangles(USACO)
- [USACO] Packing Rectangles
- USACO Packing Rectangles [cheated]
- usaco Packing Rectangles
- USACO:PROB Packing Rectangles
- USACO Packing Rectangles
- USACO-Packing Rectangles
- USACO Packing Rectangles
- USACO 1.4 Packing Rectangles
- USACO s1.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
- 地山謙 (易經大意 韓長庚)
- 第14天 Android Touch事件学习 1 点击事件
- 火天大有 (易經大意 韓長庚)
- 天火同人 (易經大意 韓長庚)
- LeetCode 041 First Missing Positive
- USACO Packing Rectangles
- flexgrid 精华(网上找不到这种案例了) 选中行 某列float数据求和 trSelected
- 天地否 (易經大意 韓長庚)
- 地天泰 (易經大意 韓長庚)
- 软件开发生命周期-2-每个阶段的利益相关方
- java学习小记 数组及其方法 结构体
- 对称博弈--取石子(七)
- maven向本地仓库导入官方仓库没有的jar包
- python decorator 计算程序时间