You work for a company that manufactures microprocessors. To assemble the microprocessors the company uses a robot made up of a single arm. The arm is connected at one of the ends ("shoulder") in a point located in the middle of the work platform, and on the other end it has a device of non-important size which can "pick up" components from the work platform ("hand"). The arm can move only horizontally, over the work platform.
The arm is made up of a series of N rigid segments of lengths L1, L2, ..., LN, connected via joints. More specifically, segment 1 is connected via a joint to the robot's shoulder, segment 2 is connected via a joint to segment 1, ..., segment N is connected via a joint to segment N-1 and has the "hand" on the other side. A joint allows the free rotation (at any angle) of the segment connected to that joint.
In order to assemble a microprocessor the robot must successively pick up its components from the work platform. Each component has a well-determined position on the work platform, via its coordinates relative to a Cartesian coordinate system, with the center in the robot's shoulder.
Your role in the company is to program the robot's moves. To this ends, for each component the robot will pick up you have to specify the "configuration" of the robot's arm which would allow it to reach said component (the robot's arm must be located above the position were the component is located).
The configuration of the robot's arm is defined by the angles between the rigid arm's segments.
Task
Write a program which, for a given position, determines a configuration for the robot arm which will allow it to pick up the component from said position if it is possible.
Input Data
Input file robot.in contains on line one a positive integer N, representing the number of segments the robot's arm is made up of.
Each of the following N lines contains a positive integer. The number located on line i+1 is the length of the i-th segment of the robot's arm.
The last line contains two positive integers, x and y, separated by a space, representing the coordinates of the position which the robot's "arm" must reach.
Output Data
Output file robot.out will contain a single line with 0 if it's not possible for the robot's arm to reach position x, y. If the problem has a solution, the output file contains N lines. Line i will contain integer value ui which represents the angle between segment i and segment i-1 (for any i from 2 to N), and value u1 represents the angle which segment 1 forms in the robot's shoulder with axis OX.
Constraints
robot.in | robot.out | robot.in | robot.out |
3 |
125.6725 0 252.5424 |
3 10 5 25 2 4 |
0 |
Time limit: 0.1 seconds/test
prof. Emanuela Cerchez
"Grigore Moisil" Iaşi IT High School
Contact:emanuela.cerchez@gmail.com