acm pku 1299 Polar Exploer的简单实现

Polar Explorer

Description

You are a intrepid 2-dimensional explorer located at the northern polar reaches of a distant 2-dimensional planet. Unfortunately, you have been assigned to explore the most boring planet in the known universe (due primarily to your lack of social skills and aggressive body odor). Having a perfectly circular surface, your planet holds no surprises for a would-be explorer.

However, you have recently received a distress call from an alien ship which has crash-landed somewhere on the surface of your planet. Unfortunately, you designed your own equipment, and the only information it will give you is an angle (measured from the center of the planet) separating you from the crash site.

Using this information along with how much gasoline is available for your planet-rover (which gets a measley 5 miles per gallon), you have to determine if you can possibly get to the crash site and back without running out of fuel.

 

Input

Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.


A single data set has 3 components:
Start line - A single line, "START".
Input line - A single line, "X Y Z", where:
X : (1 <= X <= 100) is the radius of your planet in integer miles
Y : (0 <= Y <= 100) is the amount of gasoline in your planet-rover in integer gallons
Z : (0 <= Z <= 360) is an angle separating you from the crash site in integer degrees

End line - A single line, "END".
Following the final data set will be a single line, "ENDOFINPUT".


Take note of the following:
The circumference of a circle in terms of its radius, r, is known to be 2πr
Assume that π = 3.14159

Output

For each data set, there will be exactly one line of output. If you have enough fuel to get to the crash site and back, the line will read, "YES X", where X is the amount of fuel you will have left expressed as an integer number of gallons (truncate any fractional gallons). If you do not have sufficient fuel, the line will read, "NO Y", where Y is the distance you can travel expressed as an integer number of miles.

Sample Input

START
1 100 0
END
START
10 0 1
END
START
100 50 90
END
START
100 50 270
END
ENDOFINPUT

Sample Output

YES 100
NO 0
NO 250
NO 250

Source

South Central USA 2002

 

分析: 这是一道简单易实现的计算题,题目大意就是计算汽车里的汽油是否能够到达失事飞机的地点并返回,如能则输出“Yes 所剩汽油”, 否则输出“No 汽车能行进的距离”。

这个题目唯一需要注意的就是:如果事发地与汽车位置的角度超过180度时,汽车实际上可以从另一方向前往失事地点,这个更近,即角度大于180时,真实行进角度应为360-Z

 

代码实现:

#include "string.h"

#include "iostream"

using namespace std;

 

#define PI 3.14159

 

int main(void)

{

         char start[16], end[16];

         int X, Y, Z;

         double idis, ilen;

 

         cin >> start;

         while(strcmp(start, "START") == 0)

         {

                   cin >> X >> Y >> Z;

 

                   if(Z > 180)

                            Z = 360 - Z;

                   idis = 2.0 * PI * ((double)(X * Z)) / 360.0;

                   ilen = 5 * (double)Y;

                   if(idis*2. > ilen)

                            cout << "NO " << (int)ilen << endl;

                   else

                            cout << "YES " << (int)((ilen - idis*2.)/5.) << endl;

 

                   cin >> end;

                   cin >> start;

         }

         return 0;

}

 

提交结果:

Problem: 1299

 

User: uestcshe

Memory: 212K

 

Time: 0MS

Language: C++

 

Result: Accepted

 

你可能感兴趣的:(acm)