usaco——packrec

来源:互联网 发布:杭州全速网络 编辑:程序博客网 时间:2024/04/29 21:27

图片上传不行了,有六种情况,可以去网上搜。。。

这次代码是别人的。。。

不是我不想写,是我写了,忘存了,而且这道题蛮难的,之前看了别人的思路,写了,但是到枚举时,就是列举4*3*2*1=24和2*2*2=8时觉得巨麻烦,看了网上有用for一层一层套的,有的自己列举的(汗),这个代码在这点上蛮有深度的,用的是递归函数,在2*2*2时用了位操作,超帅!但是我觉得在判断第6种情况是这段代码是有漏洞的,虽然ac了,但是我能举出一个例子让他出现非常明显的错误。今天不让上传图片,改天再添上。

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 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

 


挺帅的代码(别人的)

USACO Gateway  |   Comment or Question