acm--Mathematical geometry--The rotating problem of rings--14 provincial race in Inner Mongolia

Source: Internet
Author: User
Tags greatest common divisor

1115:problem E-Ring rotation problem time limit: 1 Sec memory limit: MB
submitted by: $6 resolution:
Submitted State [Discussion Version] Title Description

The ring is known to have the following characteristics: 1. A rotating ring turns its tangent ring at the same time. 2. Two tangent rings do not slide at the tangent point. Initially, there are two stationary rings on the plane (the input data ensures that two circles do not intersect or overlap).   After adding an external force, so that the first ring at angular velocity w dumpers. To find the angular velocity of the second ring at this time.

Input

The input contains multiple sets of data. For each set of data: The first line has two integers: x1,y1, R1 (coordinates and radii of the first ring) the second line has two integers: x2,y2, R2 (coordinates and radii of the second ring) the third line has an integer: W (the angular velocity of the first ring, negative numbers for the opposite direction) X1,y1, X2,y2 are integers and range within [0,10^8] r1,r2 are integers and 0 < R1,R2 < 10^8 W are integers and -10^8 < W < 10^8

Output

Please output the angular velocity of the second ring, if not the integer output in the simplest fraction (see example). One row for each set of data output.

Sample input
0 0 12 0 1-10 0 35 0 21


Sample output
1-3/2

Tips

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

The distance between the center of the Circle = = Two radius of the sum of the distance (W2 direction and W1 direction opposite)

Inscribed: distance between centers = = Two radius difference (the direction of W2 is the same as the direction of W1)

There is also to consider the output form of the problem: if you can divide the output directly;

Otherwise, it will be output as the simplest fraction (greatest common divisor between them, then output)

#include <cstdio> #include <string> #include <iostream> #include <cmath>typedef long ll;    Using namespace std;/** seeking greatest common divisor */ll gcd (ll A,ll b) {ll r;        while (b!=0) {r=a%b;        A=b;    B=r; } return A; /** is used to open square */ll Square (ll x) {return x*x;} /** is used to calculate the distance of two points on the coordinates */ll distance (ll x1,ll y1,ll x2,ll y2) {return square (x1-x2) +square (y1-y2);}    int main () {//First circle and second round, angular velocity ll x1,y1,r1,x2,y2,r2,w,v1,temp;        while (cin>>x1>>y1>>r1>>x2>>y2>>r2>>w) {v1=w*r1;//for outgoing speed, two round tangent, same line speed        Find out the distance between two points ll Dis=distance (x1,y1,x2,y2); if (Dis>square (R1+R2) | | | dis<square (R1-R2) | |        w==0)//Absent {printf ("0\n");            }//Out-of-box else if (Dis==square (R1+R2)) {if (w>0) printf ("-");            if (v1%r2==0) printf ("%lld\n", (LL) ABS (v1)/R2);                else{TEMP=GCD (LL) ABS (v1), R2); Divided by greatest common divisor, the aim is to get the simplest fractional printf("%lld/%lld\n", (LL) ABS (v1)/temp,r2/temp);            }}//inscribed else if (Dis==square (R1-R2)) {if (w<0) printf ("-");            if (v1%r2==0) printf ("%lld\n", (LL) ABS (v1)/R2);                else{TEMP=GCD (LL) ABS (v1), R2);            The purpose of dividing by greatest common divisor is to obtain the simplest fractional printf ("%lld/%lld\n", (LL) ABS (v1)/temp,r2/temp); }}} return 0;}




Reference Blog: http://blog.csdn.net/whjkm/article/details/40452833


acm--Mathematical geometry--The rotating problem of rings--14 provincial race in Inner Mongolia

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.