2013
11-11

POJ 2507 Crossed ladders [解题报告] Java

A narrow street is lined with tall buildings. An x foot long ladder is rested at the base of the building on the right side of the street and leans on the building on the left side. A y foot long ladder is rested at the base of the building on the left side of the street and leans on the building on the right side. The point where the two ladders cross is exactly c feet from the ground. How wide is the street?

Each line of input contains three positive floating point numbers giving the values of x, y, and c.

For each line of input, output one line with a floating point number giving the width of the street in feet, with three decimal digits in the fraction.

30 40 10
12.619429 8.163332 3
10 10 3
10 10 1


26.033
7.000
8.000
9.798


//* @author: [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
import java.io.*;
import java.util.Arrays;
public class Main
{
public static void main(String[] args) throws IOException
{
{
double x=Double.parseDouble(ss[0]);
double y=Double.parseDouble(ss[1]);
double c=Double.parseDouble(ss[2]);
double max=Math.min(x, y),min=0;
for(int i=0;max-min>0.00001;i++)
{
double mid=(min+max)/2;
double d1=Math.sqrt(x*x-mid*mid);
double d2=Math.sqrt(y*y-mid*mid);
if(c*(d1+d2)==(d1*d2)){
min=max=mid;
break;
}
else if(c*(d1+d2)>(d1*d2)) max=mid;
else min=mid;
}
System.out.printf("%.3f\n",(min+max)/2);
}
}
}

1. 其实国内大部分公司对算法都不够重视。特别是中小型公司老板根本都不懂技术，也不懂什么是算法，从而也不要求程序员懂什么算法，做程序从来不考虑性能问题，只要页面能显示出来就是好程序，这是国内的现状，很无奈。