# poj 1319 Pipe Fitters

Pipe Fitters

Time limit: 3.000 seconds

## Background背景

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

## The 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.

## The 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 27. Note that a cross section with dimensions a×b can also be viewed as a cross section with dimensions b×a.

## The 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.

3 3
2.9 10
2.9 10.5
11 11

9 grid
29 skew
30 skew
126 skew

## Analysis分析

#include<iostream>
using namespace std;
#include<math.h>
const double P=sqrt(3.0)/2.0;
const double eps=1e-8;
int main()
{
int max1,max2,max3,max,t;
double a,b;
while(cin>>a>>b)
{
max1=floor(a)*floor(b);
max2=floor(a);
t=1;
while(1)
{
t++;
if(b-(t-1)*P-1<eps)
break;
if(t%2==0)
max2+=floor(a-0.5);
else max2+=floor(a);
}
max3=floor(b);
t=1;
while(1)
{
t++;
if(a-(t-1)*P-1<eps)
break;
if(t%2==0)
max3+=floor(b-0.5);
else
max3+=floor(b);
}
max=max1;
if(max<max2)
max=max2;
if(max<max3)
max=max3;
if(a-1.0<eps||b-1.0<eps)
max=0;
if(max==max1)
cout<<max<<" "<<"grid"<<endl;
else
cout<<max<<" "<<"skew"<<endl;
}
return 0;
}

#include<iostream>
using namespace std;
#include<math.h>
const double P=sqrt(3.0)/2.0;
const double eps=1e-8;
int main()
{
int max1,max2,max3,max,t;
double a,b;
while(cin>>a>>b)
{
max1=floor(a)*floor(b);
max2=floor(a);
t=1;
while(1)
{
t++;
if(b-(t-1)*P-1<eps)
break;
if(t%2==0)
max2+=floor(a-0.5);
else max2+=floor(a);
}
max3=floor(b);
t=1;
while(1)
{
t++;
if(a-(t-1)*P-1<eps)
break;
if(t%2==0)
max3+=floor(b-0.5);
else
max3+=floor(b);
}
max=max1;
if(max<max2)
max=max2;
if(max<max3)
max=max3;
if(a-1.0<eps||b-1.0<eps)
max=0;
if(max==max1)
cout<<max<<" "<<"grid"<<endl;
else
cout<<max<<" "<<"skew"<<endl;
}
return 0;
}

• 本文已收录于以下专栏：

## F - Pipe Fitters解题报告（熊禾强）

F - Pipe Fitters Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Su...

## Hdu 1621 - Pipe Fitters 计算几何

UVa OJ 121 - Pipe Fitters (装管子) Time limit: 3.000 seconds 限时：3.000秒   Background 背景 Filte...
• yibcs
• 2012年10月04日 16:39
• 731

## POJ1039-Pipe

• 2011年07月31日 23:13
• 11KB
• 下载

## HDU1319 POJ1595 UVA406 UVALive5490 ZOJ1312 Prime Cuts【素数筛选+打表】

Prime Cuts Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11505   Ac...

## lightoj 1319 - Monkey Tradition 中国剩余定理（孙子定理）+poj 2891 Strange Way to Express Integers

#include #include #include #include using namespace std; #define LL long long LL p[13],r[13],n; ...

## POJ 1039 Pipe 计算几何题目。。

http://poj.org/problem?id=1039 叉乘真的是个好东西，把许多原来很难用计算机实验的情况编程数字的相乘，加，减，就连除几乎都没有了。。。 这题作为模板吧，因为我刚...

## poj 1039 Pipe(直线与线段交+枚举直线)

【题目大意】：给出n个水管的上接点（下接点的坐标为上接点的横坐标，和纵坐标减一），然后问你从管的左端射进一束光，在管里能够跑多远，输出到达最远点的横坐标。 【解题思路】：一开始觉得不好做，因为入口的...
• wlyqh
• 2011年11月01日 13:32
• 203

举报原因： 您举报文章：poj 1319 Pipe Fitters 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)