Rotation of problem e ring (14-year provincial competition)

Source: Internet
Author: User
1115: problem e ring Rotation Problem time limit: 1 sec memory limit: 128 MB
Submitted: 58 solution: 6
[Submit] [Status] [discussion version] Description

It is known that a ring has the following characteristics: 1. A Rotating Ring will rotate at the same time as the tangent ring. 2. The two tangent rings do not slide at the cut point. At the beginning, there are two static rings on the plane (the input data ensures that the two circles do not overlap or overlap ). Add an external force to make the first ring rotate at a constant speed at the velocity w. Returns the angular velocity of the second ring.

Input

The input contains multiple groups of data. For each group of data, the first row has two integers: X1, Y1, R1 (Coordinate and radius of the first ring), and the second row has two integers: X2, Y2, r2 (Coordinate and radius of the second ring) the third row has an integer W (the angular velocity of the first ring, negative number indicates turning in the opposite direction) x1, Y1, X2, y2 is an integer in the range of [0, 10 ^ 8] R1, R2 is an integer and 0 <R1, r2 <10 ^ 8 W is an integer and-10 ^ 8 <W <10 ^ 8

Output

Please output the angular velocity of the second ring. If it is not an integer, It is output in the form of the simplest score (see the example ). Output a row of data in each group.

Sample Input
0 0 12 0 1-10 0 35 0 21
Sample output
1-3/2

Prompt

This is a relatively simple calculation geometric question. When I did it for the first time, I forgot to consider the inner cut. I submitted the question for a long time and did not find any errors at the beginning;

In the second step, the idea was clear:

There are three main cases: Separation: the distance between the center is greater than the sum of the two radius (less than the difference between the two radius)

Outer cut: the distance between the center = the distance between the two radius (the direction of W2 is opposite to that of W1)

Inner cut: the distance between the center = the difference between two radius (W2 and W1 are in the same direction)

Another problem is that the output format should be considered: if the Division is possible, the output can be directly;

Otherwise, it is output in the form of the simplest score (calculate the maximum common number between them, and then output)

In the second step, the Code had no problem in terms of thinking, but it was still wa, (even less the error could not be found). Later, I read it again, it is found that when w = 0, the implicit condition 0 is directly output and has not been processed. When determining the separation, add this condition,. (Potholes !!) Be sure to pay attention to the details. In the future, you must focus on the ideas of the questions and train your thinking skills!

The following code is used:

# Include <cstdio> # include <string> # include <iostream> # include <cmath> typedef long ll; using namespace STD; ll gcd (ll a, LL B) // calculate the maximum common approx. {ll R; while (B! = 0) {r = A % B; A = B; B = r;} return a;} ll square (LL X) // returns the square {return x * X ;} ll distance (LL X1, ll Y1, ll X2, ll Y2) // the distance between two points {return square (x1-x2) + square (y1-y2);} int main () {ll X1, Y1, R1, X2, Y2, R2, W, V1, temp; while (CIN> x1> Y1> r1> X2> Y2> r2> W) {v1 = W * R1; ll Dis = distance (x1, y1, X2, Y2); If (DIS> Square (R1 + R2) | dis <square (r1-r2) | W = 0) // separation {printf ("0 \ n");} else if (Dis = square (R1 + R2) // returns the outer tangent {If (W> 0) printf ("-"); If (V1% r2 = 0) printf ("% LLD \ n", (LL) ABS (V1)/R2 ); else {temp = gcd (LL) ABS (V1), R2); printf ("% LLD/% LLD \ n", (LL) ABS (V1)/temp, r2/temp) ;}} else if (Dis = square (r1-r2) // inner cut {If (W <0) printf ("-"); if (V1% r2 = 0) printf ("% LLD \ n", (LL) ABS (V1)/R2); else {temp = gcd (LL) ABS (V1), R2); printf ("% LLD/% LLD \ n", (LL) ABS (V1)/temp, R2/temp );}}} return 0 ;}


Rotation of problem e ring (14-year provincial competition)

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.