首页 > 专题系列 > Java解POJ > POJ 2508 Conic distance [解题报告] Java
2013
11-11

POJ 2508 Conic distance [解题报告] Java

Conic distance

问题描述 :

A cone is located in 3D such that its base of radius r is in the z = 0 plane with the center at (0,0,0). The tip of the cone is located at (0, 0, h). Two points are given on the cone surface in conic coordinates. The conic coordinates of a point p lying on the surface of the cone are two numbers: the first, d, is the distance from the tip of the cone to p and the second, A < 360, is the angle in degrees between the plane y = 0 and the plane through points (0,0,0), (0,0,h) and p, measured counterclockwise from the direction of the x axis.



Given are two points p1 = (d1, A1) and p2 = (d2, A2) in the conic coordinates. What is the (shortest) distance between p1 and p2 measured on the surface of the cone?

输入:

The input is a sequence of lines. Each line contains 6 floating point numbers giving values of: r, h, d1, A1, d2, and A2

输出:

For each line of input, output the (shortest) distance between points p1 and p2 on the surface of the cone with the fraction rounded to 2 decimal places.

样例输入:

3.0 4.0 2.0 0.0 4.0 0.0
3.0 4.0 2.0 90.0 4.0 0.0
6.0 8.0 2.14 75.2 9.58 114.3
3.0 4.0 5.0 0.0 5.0 90.0

样例输出:

2.00
3.26
7.66
4.54

解题代码:

//* @author:
import java.util.*;
public class Main {
 
static public void main( String [] str ){
   Scanner sc = new Scanner(System.in);
   double r, h, d1, a1, d2, a2, dg, l, s, a;

   while(sc.hasNext())
   {
      r=sc.nextDouble();
      h=sc.nextDouble();
      d1=sc.nextDouble();
      a1=sc.nextDouble();
      d2=sc.nextDouble();
      a2=sc.nextDouble();
      l = Math.sqrt( r*r + h*h );
      dg = 2*r*Math.PI / l;
      a = Math.abs(a1-a2);
      if( a > 180 ) a = 360 - a;
      a = a / 360 * dg;
      s = Math.sqrt( d1*d1 + d2*d2 - 2*d1*d2*Math.cos( a ) );
	System.out.printf( "%.2f\n", s );
    }

   }
}

  1. 学算法中的数据结构学到一定程度会乐此不疲的,比如其中的2-3树,类似的红黑树,我甚至可以自己写个逻辑文件系统结构来。

  2. #include <stdio.h>
    int main()
    {
    int n,p,t[100]={1};
    for(int i=1;i<100;i++)
    t =i;
    while(scanf("%d",&n)&&n!=0){
    if(n==1)
    printf("Printing order for 1 pages:nSheet 1, front: Blank, 1n");
    else {
    if(n%4) p=n/4+1;
    else p=n/4;
    int q=4*p;
    printf("Printing order for %d pages:n",n);
    for(int i=0;i<p;i++){
    printf("Sheet %d, front: ",i+1);
    if(q>n) {printf("Blank, %dn",t[2*i+1]);}
    else {printf("%d, %dn",q,t[2*i+1]);}
    q–;//打印表前
    printf("Sheet %d, back : ",i+1);
    if(q>n) {printf("%d, Blankn",t[2*i+2]);}
    else {printf("%d, %dn",t[2*i+2],q);}
    q–;//打印表后
    }
    }
    }
    return 0;
    }

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