首页 > 专题系列 > Java解POJ > POJ 1319 Pipe Fitters [解题报告] Java
2013
11-09

POJ 1319 Pipe Fitters [解题报告] Java

Pipe Fitters

问题描述 :

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.

输入:

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.

输出:

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

解题代码:

//* @author: 
import java.util.*;
public class Main {
  static final double l = Math.sqrt(3)/2;

  static int calc( double x, double y )
{
  int a[]=new int[2], s, i;
  double h;
  if( x < 1 )
	return 0;
  a[0] = (int)x;
  a[1] = (int)(x-0.5);
  for( i=0, h=1, s=0; h<=y; h+=l, i++ )
	s += a[i%2];
  return s;
}

 public static void main(String[] args){

   Scanner in = new Scanner(System.in);
   int s1, s2, t;	
   double x, y;
   while(in.hasNext())
   {
       x=in.nextDouble();
       y=in.nextDouble();
       s1 = (int)x * (int)y;
	s2 = calc( x, y );
	if( ( t = calc( y, x ) ) > s2 )
	  s2 = t;
	if( s1 >= s2 )
         System.out.printf( "%d grid\n", s1 );
	else
	   System.out.printf( "%d skew\n", s2 );
    }
  }
}

  1. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.

  2. for(int i=1; i<=m; i++){
    for(int j=1; j<=n; j++){
    dp = dp [j-1] + 1;
    if(s1.charAt(i-1) == s3.charAt(i+j-1))
    dp = dp[i-1] + 1;
    if(s2.charAt(j-1) == s3.charAt(i+j-1))
    dp = Math.max(dp [j - 1] + 1, dp );
    }
    }
    这里的代码似乎有点问题? dp(i)(j) = dp(i)(j-1) + 1;这个例子System.out.println(ils.isInterleave("aa","dbbca", "aadbbcb"));返回的应该是false