Drawing
InterviewTime limit2sMemory limit1024 MB
Given a chain of segments with fixed lengths anchored at A0, decide whether its end can reach point An, and output every hinge position if so.
- Level
Medium5 of 10
- Topics
- Geometry, Math, Implementation
- Solved
- No attempts yet
Problem
Fleeing another hostile creature from a parallel dimension, Gordon Freeman hid in a laboratory where crystals brought from the Xen dimension had once been studied. Once he realized he was in no danger, Freeman looked around and found interesting equipment built for ultra-precise drawing of complex diagrams. However, it was not designed for ordinary drawings, and its construction prevents it from drawing some of them.
On the lab computer, Freeman found blueprints of all rooms of the federal research center. Having them printed would greatly increase his chances of survival. It is not hard to guess what he decided to do!
The drawing device works as follows. An "arm" made of metal segments connected in series by hinges is fixed at a point on the drawing plane. Let be the length of the first segment (the one attached to ), the length of the next, and so on, up to for the last one. Denote the hinge point between segments and as , and the end of the last segment as . A tool that draws a point is attached at . The control unit can place the hinge joints at points on the drawing plane if holds for all .
To draw the diagrams, Freeman needs to find out whether the device can draw all the required points. For each point he also needs the coordinates of every . Help him with this.
Input
The first line contains four integers , , , (): the coordinates of point , where the first segment is attached, and the coordinates of point , the point to be drawn.
The second line contains an integer (), the number of segments in the device. The third line contains integers (), the lengths of the segments.
Output
The first line of the output must be YES if the point can be drawn, and NO otherwise. If it can be drawn, print the coordinates of for all from to on the next lines. The answer is accepted if the distance between your points and differs from by no more than .