Ultraviolet A Problem 10180 rope crisis in ropeland! (The Crisis of the rope kingdom !)

Source: Internet
Author: User
Tags acos dot net
// Rope crisis in ropeland! (The Crisis of the rope kingdom !) // PC/ultraviolet A IDs: 111302/10180, popularity: B, success rate: average level: 2 // verdict: accepted // submission date: 2011-11-02 // UV Run Time: 0.696 S // copyright (c) 2011, Qiu. Metaphysis # Yeah dot net // [solution] // determine whether the rope needs to bypass the Column Based on the situation. If you need to bypass the column, calculate it based on the corner relationship. # Include <iostream> # include <iomanip> # include <cmath> using namespace STD; // calculate the minimum length of the rope to bypass the column. Double lineplusarc (double X1, double Y1, double X2, double Y2, double r) {// Set coordinates (x1, Y1) to vertex M, coordinates (X2, Y2) is point N, the center of the circle is O, the two teams // and the center are connected into a triangle OMN, the side length is a (Mo), B (NO ), // C (Mn), the angle C corresponding to edge C can be obtained by cosine theorem. Double A = SQRT (x1 * X1 + Y1 * Y1); Double B = SQRT (X2 * X2 + y2 * Y2); double C = SQRT (POW (x1-X2, 2) + POW (Y1-Y2, 2); double C = ACOs (A * A + B * B-c * C) /(2.0 * a * B); // If P is set to the cut point of the line l tangent to the circle through M, MPO forms a right angle // triangle, the angle corresponding to the edge MP can be easily obtained. Double anglemp = ACOs (R/A); // In the same way, record the tangent line between point N and the circle l 'and the tangent point of the circle as Q, then nqo // forms a triangle, and the angle corresponding to the edge NQ can be easily obtained. Double anglenq = ACOs (R/B); // The length of the rope part on the column can be easily obtained. Double Length = r * (c-anglemp-anglenq); // coupled with the line segment MP, the length of NQ is the minimum length of the required rope. Length + = (SQRT (A * A-R * r) + SQRT (B * B-r * r); Return length ;}// calculate the minimum length of the required rope. Double ropelength (double X1, double Y1, double X2, double Y2, double r) {// The two points are the same. If (x1 = X2 & Y1 = Y2) return 0.0; // The two points share the same abscissa and are on the same vertical line. If (x1 = x2) {// if the distance between the vertical line and the origin is less than R, the rope must bypass the column. If (x1> 0? X1: (-X1) <r) {If (Y1 * Y2> 0) return FABS (Y1-Y2); elsereturn lineplusarc (x1, Y1, X2, Y2, r);} elsereturn FABS (Y1-Y2);} // calculated based on symmetry. If (Y1 = Y2) return ropelength (Y1, X1, Y2, X2, R); // The slope of a straight line composed of M and N is not infinite, you can use an oblique truncation to represent it. The distance from the origin to the straight line can be obtained. Double slope = (double) (Y1-Y2)/(double) (x1-X2); double intercept = Y1-slope * x1; double distance = FABS (intercept) * Cos (atan (FABS (slope); // if the distance between the origin and the straight line is less than R and the two teams are on both sides of the column, the rope needs to bypass the column. // Otherwise, do not bypass the column. If (distance <r) {// if the line between the two teams is l, the intersection of the vertical line between the origin and the line L is obtained, if the positions of the two teams are greater than the vertical coordinates of the intersection or both are less than the vertical coordinates of the intersection, the two teams are on one side of the column. Double yintersection = intercept/(slope * slope + 1.0); If (Y1-yintersection) * (Y2-yintersection)> = 0.0) return SQRT (POW (x1-X2, 2) + POW (Y1-Y2, 2); elsereturn lineplusarc (x1, Y1, X2, Y2, R);} elsereturn SQRT (POW (x1-X2, 2) + POW (Y1-Y2, 2);} int main (int ac, char * AV []) {INT cases; double X1, Y1, X2, Y2, R; cout. precision (3); cout. SETF (IOs: Fixed | IOs: showpoint); CIN> cases; while (cases --) {CIN> x1> Y1> X2> Y2> r; cout <ropelength (x1, Y1, X2, Y2, R) <Endl ;} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.