# 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;
}

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

## poj 1319 Pipe Fitters

A company manufactures pipes of uniform diameter. All pipes are stored in rectangular storage contai...
• A852852852852
• 2015年08月16日 17:27
• 272

## POJ 1319 Pipe Fitters 笔记

• woniupengpeng
• 2017年05月25日 07:49
• 258

## POJ-1319:Pipe Fitters

• ZJQLOVELYY
• 2013年01月14日 13:25
• 632

## UVa 121 - Pipe Fitters

• mobius_strip
• 2014年10月19日 00:28
• 954

## Hdu 1621 - Pipe Fitters 计算几何

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

## UVa Problem 121 - Pipe Fitters

// UVa Problem 121 - Pipe Fitters // Verdict: Accepted // Submission Date: 2011-12-18 // UVa Run Tim...
• metaphysis
• 2011年12月18日 22:50
• 2183

## poj1039 Pipe (计算几何)

• Non_Cease
• 2012年07月16日 13:03
• 1861

## lightoj 1319 - Monkey Tradition （中国剩余定理）

1319 - Monkey Tradition PDF (English) Statistics Forum Time Limit: 2 second(s) Me...
• qq_28175337
• 2016年03月22日 20:45
• 206

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

F - Pipe Fitters Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Su...
• CSUST_ACM
• 2012年05月09日 07:24
• 824

## LightOJ - 1319 Monkey Tradition （中国剩余定理 模板）

LightOJ - 1319 Monkey Tradition Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld &...
• yanghui07216
• 2016年03月19日 20:03
• 437

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