首页 > 专题系列 > Java解POJ > POJ 1905 Expanding Rods [解题报告] Java
2013
11-10

POJ 1905 Expanding Rods [解题报告] Java

Expanding Rods

问题描述 :

When a thin rod of length L is heated n degrees, it expands to a new length L’=(1+n*C)*L, where C is the coefficient of heat expansion.

When a thin rod is mounted on two solid walls and then heated, it expands and takes the shape of a circular segment, the original rod being the chord of the segment.

Your task is to compute the distance by which the center of the rod is displaced.

输入:

The input contains multiple lines. Each line of input contains three non-negative numbers: the initial lenth of the rod in millimeters, the temperature change in degrees and the coefficient of heat expansion of the material. Input data guarantee that no rod expands by more than one half of its original length. The last line of input contains three negative numbers and it should not be processed.

输出:

For each line of input, output one line with the displacement of the center of the rod in millimeters with 3 digits of precision.

样例输入:

1000 100 0.0001
15000 10 0.00006
10 0 0.001
-1 -1 -1

样例输出:

61.329
225.020
0.000

解题代码:

/* @author: */
import java.util.Scanner;
public class Main{
  static final  double PI=3.1415926;
  static final  double eps=1e-6;

  public static void main(String args[])
{    
  Scanner sc=new Scanner(System.in);
  double L,n,C,M,y1,low,high,mid;
  while(true)
  {
     L=sc.nextDouble();
     n=sc.nextDouble();
     C=sc.nextDouble();
     if(L==-1&&n==-1&&C==-1)break;
     if(L<=eps||n<=eps||C<=eps)
	{
	  System.out.println("0.000");
	  continue;
	}
     M=(1+n*C)*L;
     low=0;
     high=PI;
     while(true)
     {
	mid=(low+high)/2;
	y1=M-L*mid/Math.sin(mid);
	if(Math.abs(y1)<=eps)break;
	else if(y1>0)low=mid;
	else high=mid;
     }
     System.out.printf("%.3f\n",L*Math.tan(mid/2)/2);
    }
  }
}

  1. 很高兴你会喜欢这个网站。目前还没有一个开发团队,网站是我一个人在维护,都是用的开源系统,也没有太多需要开发的部分,主要是内容整理。非常感谢你的关注。

  2. bottes vernies blanches

    I appreciate the efforts you men and women place in to share blogs on such sort of matters, it was certainly useful. Keep Posting!

  3. Thanks for taking the time to examine this, I really feel strongly about it and love studying a lot more on this topic. If possible, as you acquire experience