poj2354——Titanic

2019-07-14 00:43发布

Titanic Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2222   Accepted: 559 Description It is a historical fact that during the legendary voyage of "Titanic" the wireless telegraph machine had delivered 6 warnings about the danger of icebergs. Each of the telegraph messages described the point where an iceberg had been noticed. The first five warnings were transferred to the captain of the ship. The sixth one came late at night and a telegraph operator did not notice that the coordinates mentioned were very close to the current ship's position.

Write a program that will warn the operator about the danger of icebergs! Input The input messages are of the following format:
Message #. Received at ::. Current ship's coordinates are ^'" and ^'" . An iceberg was noticed at ^'" and ^'" . ===
Here is a positive integer, :: is the time of the message reception, ^'" and ^'" means "X1 degrees X2 minutes X3 seconds of North (South) latitude and Y1 degrees Y2 minutes Y3 seconds of East (West) longitude." Output Your program should print to the output file message in the following format:
The distance to the iceberg: miles.
Where should be the distance between the ship and the iceberg, (that is the length of the shortest path on the sphere between the ship and the iceberg). This distance should be printed up to (and correct to) two decimal digits. If this distance is less than (but not equal to!) 100 miles the program should print one more line with the text:
DANGER! Sample Input Message #513. Received at 22:30:11. Current ship's coordinates are 41^46'00" NL and 50^14'00" WL. An iceberg was noticed at 41^14'11" NL and 51^09'00" WL. === Sample Output The distance to the iceberg: 52.04 miles. DANGER! Hint For simplicity of calculations assume that the Earth is an ideal sphere with the diameter of 6875 miles completely covered with water. Also you can be sure that lines in the input file break exactly as it is shown in the input samples. The ranges of the ship and the iceberg coordinates are the same as the usual range for geographical coordinates, i.e. from 0 to 90 degrees inclusively for NL/SL and from 0 to 180 degrees inclusively for EL/WL.
这题主要是处理字符串以及球面上的面积公式,最后与100比较时,要考虑浮点数的误差。 球面距离计算公式:d(x1,y1,x2,y2)=r*arccos(sin(x1)*sin(x2)+cos(x1)*cos(x2)*cos(y1-y2)) x1,y1是纬度经度的弧度单位,r为半径 #include #include #include #include #include #include #include #include #include #include #include #include #include #define PI 3.1415927 using namespace std; double change(int a,int b,int c)//把度数换种形式 { double sum=0; sum+=a; sum+=(b*60.0+c*1.0)/3600.0; return sum; } double cal(double a,double b,double c,double d)//计算距离 { double sum; sum=6875.0*acos(cos(a/180.0*PI)*cos(c/180.0*PI)*cos((b-d)/180.0*PI)+sin(a/180.0*PI)*sin(c/180.0*PI)); return sum; } int main() { string message; while(getline(cin,message,'=')) { string tem; cin>>tem; int num[100],k=0; for(int i=0;i
我只想做个努力的人!加油!