2013
11-11

# Global Roaming

A great deal in today’s mobile communication depends on having a direct view to a satellite. For communication providers it is therefore crucial to know where their services are available.

You are to identify locations which have a direct view to a particular satellite, i.e. this satellite must be above the horizon. To make things easier you may assume that the earth is a perfect sphere with a radius of 6378 km (mountains will be added next year…). The satellite is a pointlike object above the earth’s surface.

The input file consists of several test cases. For each test case the first line contains the number of locations n to be checked followed by the position of the satellite: its latitude, its longitude (both in degrees) and its height (in km) above the earth’s surface.

Each of the following n lines contains a location on the earth’s surface: the location’s label (a sequence of less than 60 printable ASCII characters containing no whitespace characters) followed by its latitude and longitude (both in degrees).

Input is terminated by n=0.

For each test case output the number of the test case as formatted in the sample output. Then, output the locations from where the satellite is visible by printing the corresponding labels on separate lines in the same order as they appear in the input file.

Output a blank line after each test case.

3 20.0 -60.0 150000000.0
Ulm       48.406    10.002
Jakarta   -6.13     106.75
Honolulu  21.32    -157.83
2 48.4 10 0.5
Ulm       48.406    10.002
Honolulu  21.32    -157.83
0 0.0 0.0 0.0


Test case 1:
Ulm
Honolulu

Test case 2:
Ulm


//* @author:
import java.util.*;
import static java.lang.Math.*;
public class Main {
static double  a, b, c;
static double[] change( double th,double fi, double l)
{
double z = l * sin( th/180*PI );
double y = l * cos( th/180*PI ) * sin( fi/180*PI );
double x = l * cos( th/180*PI ) * cos( fi/180*PI );
return new double[]{z,y,x};
}

static public void main( String [] str ){
Scanner sc = new Scanner(System.in);

double th, fi, l;
int n,i,cas=1;
char name[]=new char[100];
while( true )
{
n=sc.nextInt();
if( n == 0 ) break;
System.out.printf( "Test case %d:\n", cas++ );
th=sc.nextDouble();
fi=sc.nextDouble();
l=sc.nextDouble();
l += 6378;
double x[]=change( th, fi, l);
for( i=0; i< n; i++ )
{
name=sc.next().toCharArray();
th=sc.nextDouble();
fi=sc.nextDouble();
double a[]=change( th, fi, 6378);
if( (x[2]-a[2])*a[2] + (x[1]-a[1])*a[1] + (x[0]-a[0])*a[0] >= 0 )
System.out.printf( "%s\n", String.valueOf(name) );
}
System.out.println();
}
}
}

1. 这道题目虽然简单，但是小编做的很到位，应该会给很多人启发吧！对于面试当中不给开辟额外空间的问题不是绝对的，实际上至少是允许少数变量存在的。之前遇到相似的问题也是恍然大悟，今天看到小编这篇文章相见恨晚。