USACO SECTION 1.4 Packing Rectangles (未完成)

Packing Rectangles
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 2
2 3
3 4
4 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)

40
4 10
5 8

 

这道题代码量有点可怕。。。。花了一整天时间也没有AC

第六种会出现重叠的情况,提交上去时前5个样例通过了,但第6个样例时算出来的面积依旧比答案小。。

可能在第六种情况那边忽略了一些特殊的情况。。

总之自己写的代码已经乱到改不下去的地步了

先放一下,以后再来看看。

最后用NOCOW上的答案AC掉的。。。心里有点不爽。。

所以代码我也等自己写出来在贴。

 

坑爹的是我考虑了旋转的情况,转或不转,4个方块一共16种情况。。每种情况用1表示要转,0表示不转,用位运算模拟了所有旋转。。

还有类似八皇后问题的回溯来排列组合4个方块的顺序,有24种情况

感觉自己想的太复杂了。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值