Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Circles Intersection

You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$.

Write a program which prints:

"2" if $B$ is in $A$,

"-2" if $A$ is in $B$, 

"1" if circumference of $A$ and $B$ intersect, and

"0" if $A$ and $B$ do not overlap.

You may assume that $A$ and $B$ are not identical.

Input

The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers:

$x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$

Output

For each dataset, print 2, -2, 1, or 0 in a line.

Sample Input

2
0.0 0.0 5.0 0.0 0.0 4.0
0.0 0.0 2.0 4.1 0.0 2.0

Output for the Sample Input

2
0



Sample input:
2
0.0 0.0 5.0 0.0 0.0 4.0
0.0 0.0 2.0 4.1 0.0 2.0


Sample output:
2
0

Submission status: Accepted

Solution code:
import math


n = int(raw_input())

for i in xrange(n):
    data = map(float, raw_input().strip().split())
    xa = data[0]
    ya = data[1]
    ra = data[2]
    xb = data[3]
    yb = data[4]
    rb = data[5]

    d = math.sqrt((xa - xb)**2 + (ya - yb)**2)
    if d < ra - rb:
        print 2

    elif d < rb - ra:
        print -2

    elif d <= ra + rb:
        print 1
    else:
        print 0

Submission status: Accepted

Solution code:
import math
n = int(raw_input())

for i in range(n):
    xa,ya,ra,xb,yb,rb = map(float, raw_input().split())
    d = math.sqrt((xa-xb)**2+(ya-yb)**2)
    if ra+rb < d:
        print 0
    elif ra >= rb:
        if d+rb < ra:
            print 2
        else:
            print 1
    elif ra < rb:
        if d+ra < rb:
            print -2
        else:
            print 1

Submission status: Accepted

Solution code:
n = input()
while n:
    xa, ya, ra, xb, yb, rb = map(float, raw_input().split())
    r = ((xa-xb)**2 + (ya-yb)**2)**.5
    if ra+rb<r: x=0
    elif ra-rb>r: x=2
    elif rb-ra>r: x=-2
    else: x=1
    print x
    n-=1

Submission status: Accepted

Solution code:
import math

def length(xa, ya, xb, yb):
  return math.sqrt((xa - xb)**2 + (ya - yb)**2)

n = int(raw_input())
for s in range(0, n):
  xa, ya, ra, xb, yb, rb = map(float, raw_input().split(' '))
  d = length(xa, ya, xb, yb)

  if ra > rb + d:
    print 2
  elif rb > ra + d:
    print -2
  elif d > ra + rb:
    print 0
  else:
    print 1

Submission status: Accepted

Solution code:
# your code goes here
import math

n = int(input())
for i in range(n):
	xa, ya, ra, xb, yb, rb = [float(x) for x in input().split(" ")]
	distance = math.sqrt((xb-xa)**2 + (yb-ya)**2)

	if distance > ra+rb:
		print(0)
	elif distance < abs(ra-rb):
		if ra > rb:
			print(2)
		elif ra < rb:
			print(-2)
		else:
			print(1)
	elif distance <= ra+rb:
		print(1)

Submission status: Accepted

Solution code:
import math

n = input()
for i in xrange(n):
    xa, ya, ra, xb, yb, rb = map(float, raw_input().split())
    l = math.hypot(xa - xb, ya - yb)
    if l + rb < ra:
        print 2
    elif l + ra < rb:
        print -2
    elif l <= ra + rb:
        print 1
    else:
        print 0

Submission status: Accepted

Solution code:
from math import hypot

n = int(input())
for i in range(n):
    xa, ya, ra, xb, yb, rb = map(float, input().split())
    d = hypot(xb - xa, yb - ya)
    if ra + rb < d:
        print(0)
    elif abs(ra - rb) <= d:
        print(1)
    elif rb < ra:
        print(2)
    else:
        print(-2)

Submission status: Accepted

Solution code:
import math
num = int(input())
for i in range(num):
    lst = list(map(float, input().split()))
    xa, ya, ra = lst[0], lst[1], lst[2]
    xb, yb, rb = lst[3], lst[4], lst[5]

    d = math.sqrt((xa - xb)**2 + (ya - yb)**2)

    if ra + rb < d:
        print(0)

    elif d + min(ra, rb) < max(ra, rb):
        if ra < rb:
            print(-2)
        else:
            print(2)

    else:
        print(1)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
write = sys.stdout.write
EPS = 1e-9
def solve():
    xa, ya, ra, xb, yb, rb = map(float, readline().split())
    d = ((xa - xb)**2 + (ya - yb)**2)**.5
    if d < rb - ra:
        write("-2\n")
    elif d < ra - rb:
        write("2\n")
    elif d > ra + rb:
        write("0\n")
    else:
        write("1\n")
T = int(readline())
for i in range(T):
    solve()

Submission status: Accepted

Solution code:
import math

n = int(input())
for i in range(0,n):
    x1,y1,r1,x2,y2,r2 = (float(x) for x in input().split())
    ans = 1
    # Bが Aの中にあるとき2、
    # AがBの中にあるとき-2、
    # AとBが共有点をもつとき1、
    # AとBが重なっていないとき0
    # 円の中心からの距離
    l = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
    if l < abs(r1 - r2):
        if r1 > r2:
            ans = 2
        elif r2 > r1:
            ans = -2
    if l > r1 + r2:
        ans = 0
    print(ans)

Submission status: Accepted

Solution code:
import math
n=int(input())
i=1
while n>=i:                                                     #終了条件
    s=list(map(float,input().split()))
    #print("s",s)
    d=math.sqrt((s[3]-s[0])*(s[3]-s[0])+(s[4]-s[1])*(s[4]-s[1]))
    #print("d",d)
    if d>s[2]+s[5]:                                             #AとBが重なっていない
        print(0)
    elif abs(s[5]-s[2])<=d<=s[2]+s[5]:                          #AとBが共有点をもつ
        print(1)
    elif d<s[2]-s[5]:                                           #BがAの中にある
        print(2)
    elif d<s[5]-s[2]:                                           #AがBの中にある
        print(-2)
    i+=1

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    xa, ya, ra, xb, yb, rb = map(float, input().split())
    d = ((xa - xb) ** 2 + (ya - yb) ** 2)**(1/2)
    if d > ra + rb:
        print(0)
    else:
        if d + rb < ra:
            print(2)
        elif d + ra < rb:
            print(-2)
        else:
            print(1)

Submission status: Accepted

Solution code:
for q in range(int(input())):
    xa, ya, ra, xb, yb, rb = map(float, input().split())
    d2 = ((xb - xa) ** 2) + ((yb - ya) ** 2)
    if rb < ra and d2 < ((ra - rb) ** 2):
        print(2)
    elif ra < rb and d2 < ((rb - ra) ** 2):
        print(-2)
    elif ((ra + rb) ** 2) < d2:
        print(0)
    else:
        print(1)

Submission status: Accepted

Solution code:
N=int(input())
for i in range(N):
    x1,y1,r1,x2,y2,r2=map(float,input().split())
    d=((x1-x2)**2+(y1-y2)**2)**0.5
    if r1-r2>d:
        if r1==r2+d:
            print("1")
        else:
            print("2")
    elif r2-r1>d:
        if r2==r1+d:
            print("1")
        else:
            print("-2")
    elif d<r1+r2:
        print("1")
    elif r1+r2==d:
        print("1")
    elif d>r1+r2:
        print("0")

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
  xa, ya, ra, xb, yb, rb = map(float, input().split())
  d = ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5
  if rb < ra and d < ra - rb:
    print("2")
  elif ra < rb and d < rb - ra:
    print("-2")
  elif d <= ra + rb:
    print("1")
  else:
    print("0")

Submission status: Accepted

Solution code:
import math

n = int(input())

for _ in range(n):
  x_a,y_a,r_a,x_b,y_b,r_b = map(float, input().split())
  r_ab_plus = r_a + r_b
  r_ab_minus = abs(r_a-r_b)
  dist_center = math.sqrt((x_a-x_b)**2 + (y_a-y_b)**2)
  if dist_center < r_ab_minus and r_a > r_b:
    print(2)
  elif dist_center < r_ab_minus and r_b > r_a:
    print(-2)
  elif r_ab_minus <= dist_center and dist_center <= r_ab_plus:
    print(1)
  else:
    print(0)

Submission status: Accepted

Solution code:
n=int(input())
for i in range(n):
    x1,y1,r1,x2,y2,r2=map(float,input().split())
    d=((x1-x2)**2+(y1-y2)**2)**0.5
    r_min=min(r1,r2)
    r_max=max(r1,r2)
    if r_max>r_min+d:
        if r1>r2:
            print(2)
        else:
            print(-2)
    elif d<=r1+r2:
        print(1)
    else:
        print(0)

Submission status: Accepted

Solution code:
n = int(input())
E = 10**-10
for i in range(n):
	xa,ya,ra,xb,yb,rb = [float(i) for i in input().split()]
	x = ((xb-xa)**2 + (yb-ya)**2)**0.5
	xmax = x+rb
	xmin = x-rb
	if ra - xmax > E:
		print(2)
	elif xmin - (-ra) < -E:
		print(-2)
	elif xmin - ra > E:
		print(0)
	else:
		print(1)

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    x1, y1, r1, x2, y2, r2 = [float(x) for x in input().split()]
    distance = ((x1 - x2)**2 + (y1 - y2)**2)**0.5
    if distance > r1 + r2:
        print(0)
    else:
        if r1 > r2 and distance + r2 < r1:
            print(2)
        elif r1 < r2 and distance + r1 < r2:
            print(-2)
        else:
            print(1)

Submission status: Accepted

Solution code:
n = int(input())

for _ in range(n):
    xa, ya, ra, xb, yb, rb = map(float, input().split())
    if xa - ra < xb - rb and xa + ra > xb + rb and ya - ra < yb - rb and ya + ra > yb + rb:
        print(2)
    elif xa - ra > xb - rb and xa + ra < xb + rb and ya - ra > yb - rb and ya + ra < yb + rb:
        print(-2)
    elif (xa - xb)**2 + (ya - yb)**2 <= (ra + rb)**2:
        print(1)
    else:
        print(0)

Submission status: Accepted

Solution code:
import math

def judge(dist, p, q):
    if p + q >= dist:
        if dist + p < q:
            ans.append(-2)
        elif dist + q < p:
            ans.append(2)
        else:
            ans.append(1)
    else:
        ans.append(0)

N = int(input())
circles = [list(map(float, input().split())) for _ in range(N)]
ans = []

for circle in circles:
    xa, ya, ra, xb, yb, rb = circle
    distance = math.sqrt((xa-xb)**2 + (ya-yb)**2)
    judge(distance, ra, rb)

print('\n'.join(map(str, ans)))

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    xa,ya,ra,xb,yb,rb = map(float, input().split())
    dr = ((xa-xb)**2+(ya-yb)**2)**0.5
    if rb > (ra+dr):
        print(-2)
        continue
    elif ra > (rb+dr):
        print(2)
        continue
    elif dr > (ra+rb):
        print(0)
        continue
    else:
        print(1)

Submission status: Accepted

Solution code:
import math
from decimal import Decimal, getcontext

getcontext().prec = 100

def solve():
    N = int(input())
    
    for _ in range(N):
        xa, ya, ra, xb, yb, rb = map(Decimal, input().split())
        t = getcontext().power(xa - xb, Decimal('2')) + getcontext().power(ya - yb, Decimal('2'))
        D = t.sqrt()
        
        if ra > D + rb:
            print('2')
        elif rb > D + ra:
            print('-2')
        elif D <= ra + rb:
            print('1')
        else:
            print('0')

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
while True:
    N=int(input())
    for i in range(N):
        x1,y1,r1,x2,y2,r2=map(float,input().split())
        d=((x1-x2)**2+(y1-y2)**2)**0.5
        if r1-r2>d:
            if r1==r2+d:
                print("1")
            else:
                print("2")
        elif r2-r1>d:
            if r2==r1+d:
                print("1")
            else:
                print("-2")
        elif d<r1+r2:
            print("1")
        elif r1+r2==d:
            print("1")
        elif d>r1+r2:
            print("0")

Submission status: Runtime Error

Solution code:
n=input()
for i in xrange(n):
	xa,ya,ra,xb,yb,rb=map(int,raw_input().split())
	d=(xa-xb)**2+(ya-yb)**2
	if d>(ra+rb)**2:
		print(0)
	elif ra>rb:
		if (ra-rb)**2>d:
			print(2)
		else:
			print(1)
	else:
		if (rb-ra)**2>d:
			print(-2)
		else:
			print(1)

Submission status: Runtime Error

Solution code:
import math
n = int(raw_input())

for i in range(n):
    xa, ya, ra, xb, yb, rb = map(float, raw_input().split(' '))
    d = math.sqrt((xa-xb)**2 + (ya-yb)**2)
    if d+rb <= ra:
        print 2
    elif: d+ra <= rb:
        print -2
    elif: d > ra+rb:
        print 0
    else:
        print 1

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <math.h>

int main(void){
	int N;
	double Xa;
	double Ya;
	double Ra;
	double Xb;
	double Yb;
	double Rb;
	double distance;
	scanf("%d",&N);
	while(N--){
		scanf("%lf%lf%lf%lf%lf%lf",&Xa,&Ya,&Ra,&Xb,&Yb,&Rb);
		distance = sqrt(pow(Xa - Xb,2.0) + pow(Ya - Yb,2.0));
		if(distance + Rb - Ra <= 10E-14){
			printf("2\n");
		} else if(distance + Ra - Rb <= 10E-14){
			printf("-2\n");
		} else if(distance - Ra - Rb <= 10E-14){
			printf("1\n");
		} else{
			printf("0\n");
		}
	}
	return 0;
}

Submission status: Runtime Error

Solution code:


import math


num = int(input())

for i in range(num):
    ax,ay,ar,bx,by,br = map(float,input().split(' '))
    d = (ax - bx)*(ax - bx) + (ay * by)
    if d < abs(br - ar):
        if ar > br:
            print(2)
        else:
            print(-2)
    elif d <= r1 + r2:
        print(1)
    else:
        print(0)

Submission status: Runtime Error

Solution code:


import math


num = int(input())

for i in range(num):
    ax,ay,ar,bx,by,br = map(float,input().split(' '))
    d = (ax - bx)*(ax - bx) + (ay * by)(ay * by)
    if d < abs(br - ar):
        if ar > br:
            print(2)
        else:
            print(-2)
    elif d <= ar + br:
        print(1)
    else:
        print(0)

Submission status: Runtime Error

Solution code:
from numpy import *
N=int(input())
x_a=[0]*N
y_a=[0]*N
r_a=[0]*N
x_b=[0]*N
y_b=[0]*N
r_b=[0]*N
for i in range(N):
    x_a[i],y_a[i],r_a[i],x_b[i],y_b[i],r_b[i]=map(float,input().split())
for i in range(N):
    a=array([x_a[i]-x_b[i],y_a[i]-y_b[i]])
    AB=linalg.norm(a)
    r_diff=abs(r_a[i]-r_b[i])
    if AB > r_a[i]+r_b[i]:
        print(0)
    elif r_a[i]+r_b[i] >= AB and AB >= r_diff:
        print(1)
    elif r_diff > AB:
        if r_a[i] > r_b[i]:
            print(2)
        else:
            print(-2)

Submission status: Runtime Error

Solution code:
from numpy import *
N=int(input())
x_a=[0]*N
y_a=[0]*N
r_a=[0]*N
x_b=[0]*N
y_b=[0]*N
r_b=[0]*N
for i in range(N):
    x_a[i],y_a[i],r_a[i],x_b[i],y_b[i],r_b[i]=map(float,input().split())
for i in range(N):
    a=array([x_a[i]-x_b[i],y_a[i]-y_b[i]])
    AB=linalg.norm(a)
    r_diff=abs(r_a[i]-r_b[i])
    if AB > r_a[i]+r_b[i]:
        print(0)
    elif r_a[i]+r_b[i] >= AB and AB >= r_diff:
        print(1)
    else:
        if r_a[i] > r_b[i]:
            print(2)
        else:
            print(-2)

Submission status: Runtime Error

Solution code:
import math
N = input()
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = math.sqrt((x[0]-x[3])**2 - (x[1]-x[4])**2)
	s = x[2]+x[5]
	r = math.fabs(x[2]-x[5])
	if r >= d:
		if x[2] > x[5]:
			print '2'
		else:
			print '-2'
		elif s < d:
			print '0'
		else:
			print '1'

Submission status: Runtime Error

Solution code:
import math
N = input()
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = math.sqrt((x[0]-x[3])**2 - (x[1]-x[4])**2)
	s = x[2]+x[5]
	r = math.fabs(x[2]-x[5])
	if r >= d:
		if x[2] > x[5]:
			print '2'
		else:
			print '-2'
	elif s < d:
		print '0'
	else:
		print '1'

Submission status: Runtime Error

Solution code:
import math
N = input()
answers = []
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = math.sqrt((x[0]-x[3])**2 - (x[1]-x[4])**2)
	s = x[2]+x[5]
	r = math.fabs(x[2]-x[5])
	if r >= d:
		if x[2] > x[5]:
			answers.append(2)
		else:
			answers.append(-2)
	elif s < d:
		answers.append(0)
	else:
		answers.append(1)
for val in answers:
	print val

Submission status: Runtime Error

Solution code:
import Math
N = input()
answers = []
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = Math.sqrt((x[0]-x[3])**2 - (x[1]-x[4])**2)
	s = x[2]+x[5]
	r = Math.fabs(x[2]-x[5])
	if r >= d:
		if x[2] > x[5]:
			answers.append(2)
		else:
			answers.append(-2)
	elif s < d:
		answers.append(0)
	else:
		answers.append(1)
for val in answers:
	print val

Submission status: Runtime Error

Solution code:
import math
N = input()
answers = []
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = Math.sqrt((x[0]-x[3])**2 - (x[1]-x[4])**2)
	s = x[2]+x[5]
	r = Math.fabs(x[2]-x[5])
	if r >= d:
		if x[2] > x[5]:
			answers.append(2)
		else:
			answers.append(-2)
	elif s < d:
		answers.append(0)
	else:
		answers.append(1)
for val in answers:
	print val

Submission status: Runtime Error

Solution code:
import math
N = input()
answers = []
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = math.fabs(sqrt((x[0]-x[3])**2 - (x[1]-x[4])**2))
	s = x[2]+x[5]
	r = math.fabs(x[2]-x[5])
	if r >= d:
		if x[2] > x[5]:
			answers.append(2)
		else:
			answers.append(-2)
	elif s < d:
		answers.append(0)
	else:
		answers.append(1)
for val in answers:
	print val

Submission status: Runtime Error

Solution code:
import math
N = input()
answers = []
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = math.fabs(math.sqrt((x[0]-x[3])**2 - (x[1]-x[4])**2))
	s = x[2]+x[5]
	r = math.fabs(x[2]-x[5])
	if r >= d:
		if x[2] > x[5]:
			answers.append(2)
		else:
			answers.append(-2)
	elif s < d:
		answers.append(0)
	else:
		answers.append(1)
for val in answers:
	print val

Submission status: Runtime Error

Solution code:
import math
N = input()
answers = []
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = math.sqrt((x[0]-x[3])**2 - (x[1]-x[4])**2))
	math.fabs(d)
	s = x[2]+x[5]
	r = math.fabs(x[2]-x[5])
	if r >= d:
		if x[2] > x[5]:
			answers.append(2)
		else:
			answers.append(-2)
	elif s < d:
		answers.append(0)
	else:
		answers.append(1)
for val in answers:
	print val

Submission status: Runtime Error

Solution code:

import sys
import math


class Circle:
    def __init__(self, x, y, r):
        self.x = x
        self.y = y
        self.r = r

    def distance(self, other):
        dx = self.x - other.x
        dy = self.y - other.y
        return math.sqrt(dx ** 2 + dy ** 2)

    def intersection(self, other):
        d = self.distance(other)
        if self.r > d + other.r:
            return 2
        elif other.r > d + self.r:
            return -2
        elif d =< self.r + other.r:
            return 1
        else:
            return 0


#input_file = open(sys.argv[1], "r")

sys.stdin.readline()

for line in sys.stdin:
    (xa, ya, ra, xb, yb, rb) = tuple(map(float, line.split(' ')))
    ca = Circle(xa, ya, ra)
    cb = Circle(xb, yb, rb)
    print ca.intersection(cb)

Submission status: Runtime Error

Solution code:
import sys
import math
n = int(raw_input())

for i in range(n):
    dist = math.sqrt((yb - ya) **2 + (xb - xa) **2)
    if dist > (ra + rb):
        return 0
    elif abs(ra - rb) <= dist <= (ra + rb):
        return 1
    elif dist < abs(ra - rb):
	if ra > rb:
            return 2
        else:
            return -2

Submission status: Runtime Error

Solution code:
import sys
import math
n = int(raw_input())

for i in range(n):
    xa,ya,ra,xb,ya,rb =	map(float,raw_input().split())
    dist = math.sqrt((yb - ya) **2 + (xb - xa) **2)
    if dist > (ra + rb):
        return 0
    elif abs(ra - rb) <= dist <= (ra + rb):
        return 1
    elif dist < abs(ra - rb):
	if ra > rb:
            return 2
        else:
            return -2

Submission status: Runtime Error

Solution code:
# your code goes here
a, b = input().split(" ")
print ("%d %d %.5f" % (int(a)/int(b), int(a)%int(b), float(a)/int(b)))