[Zhengqing] [1768] Lovely Circular And Linear

Problem Description

Lovely Circular And Linear
Time limit: 1 SecMemory limit: 128 MB

Description

Find the number of intersection points between a circle (center coordinates: (x,y), radius: r) and a line (Ax+By+C=0).

Input

Multiple test cases, processed until end of file (EOF). The input consists of one line with x, y, r, A, B, C. All data are floating-point numbers with absolute values less than or equal to 1000.

Output

Output a number representing the number of intersection points between the line and the circle.

Sample Input

1
0 0 2 1 -1 0

Sample Output

1
2

Problem Analysis

Math problem~
Determining the intersection points of a line and a circle
Just be careful when writing the formula
The rest is fine~

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
#include<math.h>
int main() {
	double x, y, r ,A ,B, C;
	double sum,gen;
	while(scanf("%lf %lf %lf %lf %lf %lf",&x,&y,&r,&A,&B,&C)!=EOF) {
		sum=A*x+B*y+C;
		gen=sqrt(A*A+B*B);
		if(sum<0)
			sum=-sum;
		if((sum/gen)<r)
			printf("2\n");
		else if((sum/gen)>r)
			printf("0\n");
		else
			printf("1\n");
	}
	return 0;
}

Problem link: ZZULI [1768] Lovely Circular And Linear

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...