UVA121 POJ1319 HDU1621 Pipe Fitters【计算几何】

509 篇文章 9 订阅
38 篇文章 3 订阅

Pipe Fitters
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 1889 Accepted: 854

Description

Filters, or programs that pass “processed” data through in some changed form, are an important class of programs in the UNIX operating system. A pipe is an operating system concept that permits data to “flow” between processes (and allows filters to be chained together easily.)
This problem involves maximizing the number of pipes that can be fit into a storage container (but it’s a pipe fitting problem, not a bin packing problem).
A company manufactures pipes of uniform diameter. All pipes are stored in rectangular storage containers, but the containers come in several different sizes. Pipes are stored in rows within a container so that there is no space between pipes in any row (there may be some space at the end of a row), i.e., all pipes in a row are tangent, or touch. Within a rectangular cross-section, pipes are stored in either a grid pattern or a skew pattern as shown below: the two left-most cross-sections are in a grid pattern, the two right-most cross-sections are in a skew pattern.
在这里插入图片描述

Note that although it may not be apparent from the diagram, there is no space between adjacent pipes in any row. The pipes in any row are tangent to (touch) the pipes in the row below (or rest on the bottom of the container). When pipes are packed into a container, there may be “left-over” space in which a pipe cannot be packed. Such left-over space is packed with padding so that the pipes cannot settle during shipping.

Input

The input is a sequence of cross-section dimensions of storage containers. Each cross-section is given as two real values on one line separated by white space. The dimensions are expressed in units of pipe diameters. All dimensions will be less than 128. Note that a cross section with dimensions a*b can also be viewed as a cross section with dimensions b * a.

Output

For each cross-section in the input, your program should print the maximum number of pipes that can be packed into that cross section. The number of pipes is an integer – no fractional pipes can be packed. The maximum number is followed by the word “grid” if a grid pattern results in the maximal number of pipes or the word “skew” if a skew pattern results in the maximal number of pipes. If the pattern doesn’t matter, that is the same number of pipes can be packed with either a grid or skew pattern, then the word “grid” should be printed.

Sample Input

3 3
2.9 10
2.9 10.5
11 11

Sample Output

9 grid
29 skew
30 skew
126 skew

Source

Duke Internet Programming Contest 1993,UVA 121

问题链接UVA121 POJ1319 HDU1621 Pipe Fitters
问题简述:(略)
问题分析:计算几何问题,不解释。
程序说明:(略)
参考链接:(略)
题记:程序代码要尽量写得简单。

AC的C++语言程序如下:

/* UVA121 POJ1319 HDU1621 Pipe Fitters */

#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

const double DR = sqrt(3) / 2;

inline int getgrid(double w, double h)
{
    return floor(w) * floor(h);
}

int getskew(double w, double h)
{
    int w1 = floor(w), w2 = floor(w - 0.5);
    int ret = 0, even = 1;
    double r = 0;
    for (;;) {
        if (r + 1 > h) break;
        r += DR;
        ret += even ? w1 : w2;
        even = 1 - even;
    }
    return ret;
}

int main()
{
    double w, h;
    while (~scanf("%lf%lf", &w, &h)) {
        int grid = getgrid(w, h);
        int skew = max(getskew(h, w), getskew(w, h));

        if (grid >= skew) printf("%d grid\n", grid);
        else printf("%d skew\n", skew);
    }

    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值